Page 6 of 7

ACM-499 What's The Frequency, Kenneth?

Posted: Tue Aug 14, 2012 9:00 pm
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;
}

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

Posted: Tue Aug 14, 2012 11:01 pm
by brianfry713
Don't double post.

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

Posted: Tue Aug 14, 2012 11:29 pm
by brianfry713
Doesn't match the sample I/O.

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

Posted: Wed Aug 15, 2012 10:41 am
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 ?

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

Posted: Wed Aug 15, 2012 11:05 pm
by brianfry713
Doesn't match the sample I/O. Post your complete updated code.

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

Posted: Thu Aug 16, 2012 1:14 am
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;
}

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

Posted: Thu Aug 16, 2012 11:38 pm
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]).

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

Posted: Tue Aug 21, 2012 11:17 pm
by sophi
Thanks a lot @brianfry713 . I got AC :)

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

Posted: Wed Oct 31, 2012 5:06 pm
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 ;
}

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

Posted: Wed Oct 31, 2012 9:51 pm
by brianfry713
Try input:

Code: Select all

A.
AC output:

Code: Select all

A 1

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

Posted: Fri Feb 15, 2013 7:11 pm
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

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

Posted: Wed Nov 13, 2013 8:50 pm
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;
	}
}

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

Posted: Wed Nov 13, 2013 9:00 pm
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;		
	}	
}

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

Posted: Wed Nov 13, 2013 11:05 pm
by brianfry713
On 499 don't read from a file.

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

Posted: Wed Nov 13, 2013 11:12 pm
by brianfry713
On 10300 (and all problems) print a newline char at the end of the last line.