## 10062 - Tell me the frequencies!

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10062 - Tell Me the Frequencies!

A blank line should separate each set of output.

Don't print an extra blank line at the end.
Check input and AC output for thousands of problems on uDebug!

New poster
Posts: 16
Joined: Thu Oct 10, 2013 8:06 am

### Re: 10062 - Tell Me the Frequencies!

thanks brianfry713.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10062 - Tell Me the Frequencies!

Input:

Code: Select all

``````A
B
``````
AC output:

Code: Select all

``````65 1

66 1
32 1
``````
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10062 - Tell Me the Frequencies!

brianfry713 wrote:Input:

Code: Select all

``````A
B
``````
AC output:

Code: Select all

``````65 1

66 1
32 1
``````
Thank you very much for this test case, brianfry713. I hadn't considered that there might be spaces before the alphabets or punctuation.
Check input and AC output for over 7,500 problems on uDebug!

RookiE3
New poster
Posts: 16
Joined: Tue Feb 18, 2014 7:59 pm

### Re: 10062 - Tell Me the Frequencies!

Can anybody please tell me what am I doing wrong here:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct ascii_freq
{
int ascii;
int freq;
};

bool compare (const ascii_freq &a, const ascii_freq &b)
{
if(a.freq != b.freq)
return a.freq < b.freq;

return a.ascii > b.ascii;
}

int main()
{
// freopen("input.txt", "r", stdin);

bool firsttime = true;
char line[1001];
int i;
vector<ascii_freq> V;

while(gets(line))
{
if(!firsttime)
puts("\n");
int vindex = 0;

for(i=0; line!=0; i++)
{
{
ascii_freq temp;
temp.ascii = line;
temp.freq = 1;
V.push_back(temp);
vindex++;
}
else
{
}
}
sort(V.begin(), V.end(), compare);
for(i=0; i<V.size(); i++)
{
printf("%d %d", V.ascii, V.freq);
if(i < V.size()-1)
puts("");
}

V.clear();
firsttime = false;
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10062 - Tell Me the Frequencies!

Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

TLEorWA
New poster
Posts: 12
Joined: Sat Mar 01, 2014 12:56 pm

### Re: 10062 - Tell Me the Frequencies!

AC.........
tnx v1n1t
Last edited by TLEorWA on Mon Mar 24, 2014 7:08 pm, edited 1 time in total.

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10062 - Tell Me the Frequencies!

TLEorWA wrote:Why Runtime Error,what is the problem
Your code seg faults on the sample input. You might want to begin there.
Check input and AC output for over 7,500 problems on uDebug!

abccoder
New poster
Posts: 2
Joined: Mon Sep 15, 2014 1:30 pm

### 10062 - Tell me the frequencies!

whats wrong in my code?i got wrong answer

Code: Select all

``````#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

bool cmp(const pair<int, int>  &p1, const pair<int, int> &p2)
{
return p1.second < p2.second;
}

int main()
{
string n;
int ascii[1001],i,j,m,l,temp,f=1;
map <int, int> c;
vector<pair<int, int> > v;
std::map < int, int >::iterator it;
while(getline(cin,n))
{
l=n.length();
m=0;
c.clear();
v.clear();

for(i=0;i<l;i++)
{
if(n[i]!=' '&&((int)n[i]>=32)&&((int)n[i]<=128))
{
c[n[i]]=1;
for(j=i+1;j<l;j++)
{
if(n[i]==n[j])
{
c[(int)n[i]]++;
n[j]=' ';

}

}
}
}
copy(c.begin(), c.end(), back_inserter(v));

sort(v.begin(), v.end(), cmp);
if(f++>1)
cout<<endl;

for(int i = 0; i < v.size(); ++i)
cout<<v[i].first <<" "<<v[i].second<<endl;
}

return 0;
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10062 - Tell me the frequencies!

You should count space = ASCII 32
Check input and AC output for thousands of problems on uDebug!

code88045
New poster
Posts: 1
Joined: Thu May 07, 2015 7:38 am