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!

Post by brianfry713 » Fri Nov 22, 2013 9:47 pm

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!

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

Re: 10062 - Tell Me the Frequencies!

Post by sadmansobhan » Sun Nov 24, 2013 7:01 pm

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!

Post by brianfry713 » Thu Jan 23, 2014 9:44 pm

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!

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

Re: 10062 - Tell Me the Frequencies!

Post by uDebug » Fri Jan 24, 2014 7:25 am

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!

Find us on Facebook. Follow us on Twitter.

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

Re: 10062 - Tell Me the Frequencies!

Post by RookiE3 » Tue Feb 18, 2014 8:12 pm

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;
}

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

Re: 10062 - Tell Me the Frequencies!

Post by brianfry713 » Tue Feb 18, 2014 9:51 pm

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!

Post by TLEorWA » Mon Mar 24, 2014 5:00 pm

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

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

Re: 10062 - Tell Me the Frequencies!

Post by uDebug » Mon Mar 24, 2014 5:09 pm

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!

Find us on Facebook. Follow us on Twitter.

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

10062 - Tell me the frequencies!

Post by abccoder » Thu Sep 25, 2014 3:00 pm

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!

Post by brianfry713 » Fri Sep 26, 2014 12:18 am

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

Re: 10062 - Tell me the frequencies!

Post by code88045 » Thu May 07, 2015 7:43 am


Post Reply

Return to “Volume 100 (10000-10099)”