499 - What's The Frequency, Kenneth?

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

Moderator: Board moderators

sophi
New poster
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

ACM-499 What's The Frequency, Kenneth?

Post by sophi »

My output matches with UVA toolkit but I got WA . But can't find out what's the problem is.
Help please.

Code: Select all

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int main()
{
    char str[500],ch;
    int arr[52];
    int index,k,j;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(gets(str)!=NULL)
        {
            int length = strlen(str);
         

            for(k=0;k<=52;k++) arr[k]=0;

            for(j=0;j<length;j++)
                {
                   ch =str[j];

                   if(ch>=65 && ch <=90)
                    {

                        index =ch-65+26;
                        arr[index]+=1;

                    }

                    if(ch>=97 && ch<=122)
                        {
                            index = ch-97;
                            arr[index]++;
                        }
                }
                

                 int mi=0;
                 int i;
                 char c;

                for(i=0;i<52;i++)
                {
                    if(arr[mi] < arr[i])
                        {
                           mi=i;
                        }

                }


                        for(i=26;i<52;i++)
                        if(arr[mi]==arr[i])
                            {

                                c=65+i-26;
                                printf("%c",c);


                           }


                            for(i=0;i<26;i++)
                            if(arr[mi]==arr[i])
                            {
                                c=97+i;
                                printf("%c",c);

                            }

                printf(" %d\n",arr[mi]);

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

Re: ACM-499 What's The Frequency, Kenneth?

Post by brianfry713 »

Don't double post.
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Post by brianfry713 »

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!
sophi
New poster
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Post by sophi »

I changed my while loop like that

Code: Select all

while(gets(str)!=NULL)
Now it matches the sample I/O But again WA
what's the problem now ?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Post by brianfry713 »

Doesn't match the sample I/O. Post your complete updated code.
Check input and AC output for thousands of problems on uDebug!
sophi
New poster
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Post by sophi »

My Complete code is given here.My I/O matches with the I/O given by @ PromeNabid previously in this topic.

Code: Select all

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int main()
{
    char str[500],ch;
    int arr[52];
    int index,k,j;

   
      /*
         freopen("input.txt","r",stdin);
         freopen("output.txt","w",stdout);
      */

    while(gets(str)!=NULL)
        {
            int length = strlen(str);
            //if() continue;

            for(k=0;k<=52;k++) arr[k]=0;

            for(j=0;j<length;j++)
                {
                   ch =str[j];

                   if(ch>=65 && ch <=90)
                    {

                        index =ch-65+26;
                        arr[index]+=1;

                    }

                    if(ch>=97 && ch<=122)
                        {
                            index = ch-97;
                            arr[index]++;
                        }
                }
                

                 int mi=0;
                 int i;
                 char c;

                for(i=0;i<52;i++)
                {
                    if(arr[mi] < arr[i])
                        {
                           mi=i;
                        }

                }


                        for(i=26;i<52;i++)
                        if(arr[mi]==arr[i])
                            {

                                c=65+i-26;
                                printf("%c",c);


                           }


                            for(i=0;i<26;i++)
                            if(arr[mi]==arr[i])
                            {
                                c=97+i;
                                printf("%c",c);

                            }

                printf(" %d\n",arr[mi]);

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

Re: 499 - What's The Frequency, Kenneth?

Post by brianfry713 »

On line 24 you clear arr[52], which is not part of an array declared as int arr[52]; (valid are arr[0] through arr[51]).
Check input and AC output for thousands of problems on uDebug!
sophi
New poster
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Post by sophi »

Thanks a lot @brianfry713 . I got AC :)
ma7modx
New poster
Posts: 1
Joined: Wed Oct 31, 2012 2:54 am

Re: 499 - What's The Frequency, Kenneth?

Post by ma7modx »

whats the problem with my code (WA) ?

Code: Select all

#include <iostream>
#include <string>
#include <utility>
#include <string.h>
#include <algorithm>
using namespace std ;
int main()
{
	string name ;
	while(getline(cin,name) && name.size() )
	{
		int max = 0 ;
		int table [100000] ;
		memset(table,0,sizeof(table));
		string out ;
		
		for(int x = 0 ; x < name.size() ; ++x)
		{
			table[ name[x] ] ++ ;

			if(table[ name[x] ] > max && ((name[x]>='a' && name[x]<='z')||(name[x]>='A' && name[x]<='Z')))
			{
				max = table[ name[x] ] ;
				out.erase(out.begin(),out.end());
				out+=name[x] ;
			}
			else if(table[ name[x] ] == max)
				out+=name[x] ;
		}
		sort(out.begin() , out.end());
		
	
			cout << out <<" "<< max <<endl ;


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

Re: 499 - What's The Frequency, Kenneth?

Post by brianfry713 »

Try input:

Code: Select all

A.
AC output:

Code: Select all

A 1
Check input and AC output for thousands of problems on uDebug!
alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: 499 - What's The Frequency, Kenneth?

Post by alimbubt »

Some Critical Input that harassed me....
Input:

Code: Select all

,,alim..ALIM
@@alim0123alim%%alim...AALL
..alim222.. .. .. &&alim..AAFFGG
Bangladesh University of Business & Technology
(Alim)(Alim)(Alim)  aa
(Alim) (Alim)()
Output:

Code: Select all

AILMailm 1
alim 3
AFGailm 2
s 5
Alim 3
Alim 2
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
luijhy_9234
New poster
Posts: 4
Joined: Wed Nov 13, 2013 8:47 pm

Re: 499 - What's The Frequency, Kenneth?

Post by luijhy_9234 »

please, some help with my code

Code: Select all

#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
bool cmp2(int a,int b)
{
	return a<b;
}
main(){
	pair<int,char> M[75];
	char linea[75];
	int puntero=0;
	int punt=0;
	bool bandera;
	vector<int >p1;
	vector<char>p2;
	while(gets(linea)!=NULL){
		puntero=0;
		punt=0;
		p1.clear();
		p2.clear();
		for(int i = 0;i < 75;i++){
			M[i].first=0;
			M[i].second=NULL;
		}
		for(int i = 0;i < strlen(linea);i++){
			bandera=false;
			if(isalpha(linea[i])){
				for(int j = 0;j <= i;j++){
					if(linea[i]==M[j].second){
						M[j].first++;
						bandera = true;
						break;
					}
				}
				if(bandera==false)
				{
					M[puntero] = make_pair(1,linea[i]);
					puntero++;
				}
				
			}
		}
		
		for(int i = 0;i < puntero ; i++)
		{
			p1.push_back(M[i].first);
		}
		
		sort(p1.begin(),p1.end(),cmp)	;

		for(int i = 0; i < puntero;i++)
	    	if (p1[0]==M[i].first)
	    		p2.push_back(M[i].second);
	    sort(p2.begin(),p2.end(),cmp2);
	    for(int i = 0; i < p2.size();i++)
	    	cout<<p2[i];
			
	    cout<<" "<<p1[0]<<endl;
	}
}
Last edited by luijhy_9234 on Sat Mar 29, 2014 9:41 pm, edited 1 time in total.
luijhy_9234
New poster
Posts: 4
Joined: Wed Nov 13, 2013 8:47 pm

Re: 499 - What's The Frequency, Kenneth?

Post by luijhy_9234 »

some help with mi code,please

Code: Select all

#include<bits/stdc++.h>
using namespace std;
main(){
	//freopen("10300.c","r",stdin);
	int N,cont;
	cin>>N;
	int F[N];
	for(int i = 0;i < N;i++){
		cont=0;
		cin>>F[i];
		int S[F[i]];
		int A[F[i]];
		int E[F[i]];
		for(int j = 0;j < F[i];j++){
			cin>>S[j]>>A[j]>>E[j];
			cont+=S[j]*E[j];
		}
		if(i==N-1){
			cout<<cont;
			break;
		}
		cout<<cont<<endl;		
	}	
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Post by brianfry713 »

On 499 don't read from a file.
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Post by brianfry713 »

On 10300 (and all problems) print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 4 (400-499)”