Page 1 of 2

11577 - Letter Frequency

Posted: Sat Mar 28, 2009 7:18 pm
I am getting WA in this problem.As far as I have checked my outputs are ok.Can anyone give me any suggestion.My code is given below:-

Code: Select all

``````Accepted.

``````
Thanks a lot

Re: 11577-Letter Frequency

Posted: Sun Mar 29, 2009 8:58 am
change scanf("%d",&count); to scanf("%d\n",&count); get Acc and delete your code

Re: 11577 - Letter Frequency

Posted: Sat Apr 11, 2009 8:56 pm
i am repeatedly getting wrong answer.but cant find any mistake.here is my code.

#include<stdio.h>

int array[26];
int main(void)
{
int testcase,testcount=1,i;
char ch,dummy,largest;
scanf("%d\n",&testcase);
dummy=getchar();
while(testcount<=testcase)
{

scanf("%c",&ch);
if(ch=='\n')
{
largest=array[0];
for(i=1;i<=25;i++)
{
if(array>largest)
{
largest=array;

}
}
for(i=0;i<=25;i++)
{
if(array==largest)
{
printf("%c",(i+97));
}
}

testcount++;
printf("\n");
for(i=0;i<=25;i++)
{
array=0;
}
}

else
{
if(ch>='a'&&ch<='z')
{
array[ch-'a']++;
}
else if(ch>='A'&&ch<='Z')
{
array[ch-'A']++;
}

}

}
return 0;
}

Re: 11577 - Letter Frequency

Posted: Sun Apr 12, 2009 3:27 am
Try this case

1
a

Re: 11577 - Letter Frequency

Posted: Sat Dec 05, 2009 3:51 am
Hello. I've tried to solve this problem, but I continue to get a Wrong Answer. Any assistance is appreciated, since I can't even find a case where I get a wrong answer.

Thank you,
fitzpatr

Code: Select all

``````#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char input[201];
char alphabet[26]="abcdefghijklmnopqrstuvwxyz";
char *p, *q;
int x, y, z, length, highest, localCount, cases;
int num[26];
scanf("%d",&cases);
fflush(stdin);
for(z=0; z < cases; z++){
highest = 0;
gets(input);
length = strlen(input);
p = alphabet;
q = input;
for(x = 0; x < 26; x++)
{
localCount=0;
num[x] = 0;
q = input;
for(y = 0; y < length; y++)
{
if(*p == tolower(*q))
{
num[x]++;
localCount++;
}
q++;
}
p++;
if(localCount>highest)
highest = localCount;
}
if(highest !=0){
for(x = 0; x < 26; x++)
{
if(num[x] == highest)
{
printf("%c",alphabet[x]);
}
}
}
printf("\n");
}
return 0;
}

``````

Re: 11577 - Letter Frequency

Posted: Thu Jul 01, 2010 10:05 pm
try this:-
input:
5
afafafafsdaf
dsgsdagsdag
ssfde
nnaaaann

Output will be:
af
dgs
s
an

Re: 11577 - Letter Frequency

Posted: Thu Feb 10, 2011 2:32 am
i really disappointed
every try in this problem , got WA
i tried all test cases
like
1
a
and mr naseef_07cuet cases
and all correct
but finally got WA
any one could
any one could help ?!!!
my code >>

Code: Select all

``````#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
void INSERTION_SORT(char[],int) ;
using namespace std ;
int main ()
{
int Cnt = 0  , freq = 0,oo =-1000,Cases,index=0,LettCnt=0;
char c;
char Arr[200],Lett[100];
char Comp ;
int Count [200];
cin>>Cases;
for (int K=0;K<Cases+1;K++)
{
for (int i=0; i<200; i++)
{
scanf("%c", &c);
Arr[i] = c;
Cnt++;
if (c == '\n')
break;
}
for (int i=Cnt;i<200;i++)
{
Arr[i] = '\0';
}
for (int i=0;i<Cnt;i++)
{
if (isdigit(Arr[i])||Arr[i]==' '||Arr[i]=='\n')
{
Count[i]=oo;
}
else
{
Count[i] = 1;
}
}
for (int i=Cnt;i<200;i++)
{
Count[i] = '\0';
}
for (int i=0;i<Cnt;i++)
{
Comp = Arr[i];
for (int j=i+1;j!=Cnt+1;j++)
{
if (Arr[j]==Comp)
{
Count[i]++;
}
}
}
for (int i=0;i<Cnt;i++)
{
if (Count[i]>freq)
{
freq = Count[i];
}
}
for (int i=0;i<Cnt;i++)
{
if (Count[i]==freq)
{
Lett[LettCnt++]=Arr[i];
index++;
}
}
if(K!=0)
{
INSERTION_SORT(Lett,index);
//		if(K!=Cases)
//		{
cout<<endl;
//		}
}
//========================= Re Initialize Arrays & Data =================
for (int i=0;i<Cnt;i++)
{
Arr[i] = '\0';
Count[i]= '\0';
}
for (int i=0;i<index;i++)
{
Lett[i] = '\0';
}
freq = 0;
Cnt = 0;
oo = -1000;
LettCnt=0;
index=0;
}
return 0 ;
}
void INSERTION_SORT(char Array[],int ArrayLength)
{
for(int j=1;j<ArrayLength;j++)
{
int key=Array[j];
int i=j-1;
while(i>=0&&Array[i]>key)
{
Array[i+1]=Array[i--];
}
Array[++i]=key;
}
for (int i=0;i<ArrayLength;i++)
{
cout<<Array[i];
}
}
``````

11577 - Letter Frequency

Posted: Tue Dec 04, 2012 8:33 am
Hi,

I got TL.

I am sure that complexity of my solution is n+nlogn. Is it enough? or there is exits faster algorithm
Or this is Java I/O problems?

Code: Select all

``````AC
``````

Re: 11577 - Letter Frequency TLE

Posted: Sat Dec 08, 2012 8:04 am
you can solve it in JAVA in less than .3 sec. Just keep an array of size 26 with all the frequencies.

Re: 11577 - Letter Frequency TLE

Posted: Sun Dec 09, 2012 5:26 am
Thank you.
Got AC

Re: 11577 - Letter Frequency

Posted: Thu Aug 15, 2013 1:25 pm
what's wrong... i get many wa.

Code: Select all

``````#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
freopen("uvainput.txt", "r", stdin);
//freopen("uvaoutput.txt", "w", stdout);

char s[10000],rs[30],tch;
int t,tt,i,j,l,max,min,c;

const int r=123;
scanf("%d",&tt);
char gr=getchar();

for(t=1; t<=tt; t++)
{
max=0,c=0;
int a[r]={0};
gets(s);
l=strlen(s);

for(i=0;i<l;i++)
{
if(isalpha(s[i]))
{
if(isupper(s[i]))
{
j=s[i]+32;
}
else
j=s[i];
a[j]++;
}
}
//65 to 122

for(i=65;i<r;i++)
{
if(a[i]>max)
max=a[i];
}

for(i=65;i<r;i++)
{
if(a[i]==max)
{
rs[c]=i;
c++;
}
}

for(i=0; i<c-1; i++)
{
min=rs[i];
for(j=i+1; j<c; j++)
{
if(rs[j]<min)
{
min= rs[j];
tch=rs[i];
rs[i]=rs[j];
rs[j]=tch;
}
}
}

for(i=0; i<c; i++)
{
printf("%c",rs[i]);
}

}

return 0;
}``````

Re: 11577 - Letter Frequency

Posted: Thu Aug 15, 2013 11:16 pm

11577 - Letter Frequency

Posted: Wed May 07, 2014 1:20 pm

Code: Select all

``````#include <stdio.h>
#include <ctype.h>
int main(){
int n;
scanf("%d",&n);
getchar();
while(n--){
char s[1000],cnt[26]={0};
gets(s);
int i;
for(i=0;s[i];i++){
if(s[i]>='A' && s[i]<='Z'){
cnt[s[i]-'A']++;
}
else if(s[i]>='a' && s[i]<='z'){
cnt[s[i]-'a']++;
}
}
int max=cnt[0];
for(i=0;i<26;i++){
if(cnt[i]>max){
max=cnt[i];
}
}
for(i=0;i<26;i++){
if(cnt[i]==max){
printf("%c",i+'a');
}
}
printf("\n");

}
return 0;
}
``````

11577 - Letter Frequency help me :'(

Posted: Wed May 07, 2014 5:47 pm
Who can help me I can't find error.

Code: Select all

``````#include <stdio.h>
#include <ctype.h>
int main(){
int n;
scanf("%d",&n);
getchar();
while(n--){
char s[1000],cnt[26]={0};
gets(s);
int i;
for(i=0;s[i];i++){
if(s[i]>='A' && s[i]<='Z'){
cnt[s[i]-'A']++;
}
else if(s[i]>='a' && s[i]<='z'){
cnt[s[i]-'a']++;
}
}
int max=cnt[0];
for(i=0;i<26;i++){
if(cnt[i]>max){
max=cnt[i];
}
}
for(i=0;i<26;i++){
if(cnt[i]==max){
printf("%c",i+'a');
}
}
printf("\n");

}
return 0;
}``````

Re: 11577 - Letter Frequency

Posted: Wed May 07, 2014 9:17 pm
Don't double post.