Page 16 of 16
Re: 10062 - Tell Me the Frequencies!
Posted: Fri Nov 22, 2013 9:47 pm
by brianfry713
A blank line should separate each set of output.
Don't print an extra blank line at the end.
Re: 10062 - Tell Me the Frequencies!
Posted: Sun Nov 24, 2013 7:01 pm
by sadmansobhan
thanks brianfry713.
Re: 10062 - Tell Me the Frequencies!
Posted: Thu Jan 23, 2014 9:44 pm
by brianfry713
Re: 10062 - Tell Me the Frequencies!
Posted: Fri Jan 24, 2014 7:25 am
by uDebug
brianfry713 wrote:Input:
AC output:
Thank you very much for this test case,
brianfry713. I hadn't considered that there might be spaces
before the alphabets or punctuation.
Re: 10062 - Tell Me the Frequencies!
Posted: Tue Feb 18, 2014 8:12 pm
by RookiE3
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 address[128];
int vindex = 0;
memset(address, -1, sizeof(address));
for(i=0; line!=0; i++)
{
if(address[line] == -1)
{
ascii_freq temp;
temp.ascii = line;
temp.freq = 1;
V.push_back(temp);
address[line] = vindex;
vindex++;
}
else
{
V[address[line]].freq++;
}
}
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;
}
Re: 10062 - Tell Me the Frequencies!
Posted: Tue Feb 18, 2014 9:51 pm
by brianfry713
Print a newline char at the end of the last line.
Re: 10062 - Tell Me the Frequencies!
Posted: Mon Mar 24, 2014 5:00 pm
by TLEorWA
AC.........
tnx v1n1t

Re: 10062 - Tell Me the Frequencies!
Posted: Mon Mar 24, 2014 5:09 pm
by uDebug
TLEorWA wrote:Why Runtime Error,what is the problem
Your code seg faults on the sample input. You might want to begin there.
10062 - Tell me the frequencies!
Posted: Thu Sep 25, 2014 3:00 pm
by abccoder
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;
}
Re: 10062 - Tell me the frequencies!
Posted: Fri Sep 26, 2014 12:18 am
by brianfry713
You should count space = ASCII 32
Re: 10062 - Tell me the frequencies!
Posted: Thu May 07, 2015 7:43 am
by code88045