499 - What's The Frequency, Kenneth?
Moderator: Board moderators
499 SOS
Hi everybody!
I'm feed up of #499 as i can't make out what's wrong with my code - i get WA-. The only part i'm not sure about it is the way the program may end executing (ive tried with while(cin) and While(!feof(stdin)) ). Please help
#include <stdio.h>
#include <iostream.h>
#include <string.h>
void main()
{
int llista[52],sol[52],i,veg,repe,mi,ma,j,swap,min,k,lon;
char x[128],resp;
while (cin)
{
cin.getline(x,128,'\n');
lon=strlen(x);
for(k=0; k<52; k++)
llista[k]=llista[k]^llista[k];
for(k=0; k<lon; k++)
{
ma= ((int) x[k])-'A';mi= ((int) x[k])-'a';
if( (ma<26) && (ma >=0) ) llista[ma]++;
else if( (mi< 26) && (mi>=0) ) llista[mi+26]++;
}
veg=veg^veg; sol[0]=sol[0]^sol[0]; repe=repe^repe;
for( i=0; i<52; i++)
{
if( llista>veg ){ veg=llista; sol[0]=i; repe=repe^repe;}
else if( llista==veg ){ repe++; sol[repe]=i;}
}
for(i=0; i<=repe; i++)
{
min=sol;swap=i;
for(j=i+1; j<=repe; j++)
if(sol[j]<min) {min=sol[j];swap=j;}
sol[swap]=sol; sol=min;
}
if(lon==0)
{
cout<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0"<<endl;
}
else
{
for (i=0; i<=repe; i++)
{
if(sol>25) resp=(char)(sol-26+'a');
else resp=(char)(sol+'A');
cout<<resp;
}
cout<<" "<<veg<<endl;
}
}
}
I'm feed up of #499 as i can't make out what's wrong with my code - i get WA-. The only part i'm not sure about it is the way the program may end executing (ive tried with while(cin) and While(!feof(stdin)) ). Please help
#include <stdio.h>
#include <iostream.h>
#include <string.h>
void main()
{
int llista[52],sol[52],i,veg,repe,mi,ma,j,swap,min,k,lon;
char x[128],resp;
while (cin)
{
cin.getline(x,128,'\n');
lon=strlen(x);
for(k=0; k<52; k++)
llista[k]=llista[k]^llista[k];
for(k=0; k<lon; k++)
{
ma= ((int) x[k])-'A';mi= ((int) x[k])-'a';
if( (ma<26) && (ma >=0) ) llista[ma]++;
else if( (mi< 26) && (mi>=0) ) llista[mi+26]++;
}
veg=veg^veg; sol[0]=sol[0]^sol[0]; repe=repe^repe;
for( i=0; i<52; i++)
{
if( llista>veg ){ veg=llista; sol[0]=i; repe=repe^repe;}
else if( llista==veg ){ repe++; sol[repe]=i;}
}
for(i=0; i<=repe; i++)
{
min=sol;swap=i;
for(j=i+1; j<=repe; j++)
if(sol[j]<min) {min=sol[j];swap=j;}
sol[swap]=sol; sol=min;
}
if(lon==0)
{
cout<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0"<<endl;
}
else
{
for (i=0; i<=repe; i++)
{
if(sol>25) resp=(char)(sol-26+'a');
else resp=(char)(sol+'A');
cout<<resp;
}
cout<<" "<<veg<<endl;
}
}
}
Code: Select all
The only part i'm not sure about it is the way the program may end executing (ive tried with while(cin) and While(!feof(stdin)) ).
Just two changes and you'll get ACC.
1) Read simply by using stdio.h.
Just do this :
Code: Select all
while (gets(x)) {
/* YOUR CODE */ ;
}
should remove the first line in your while, which is :
Code: Select all
cin.getline(x,128,'\n');
Without these changes your program was giving WA
in the case when after the last line in INPUT there's
no NEWLINE character, but just directly an EOF.
Maybe it was giving WAs in other test cases too.
499 WA
please help
Code: Select all
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
string s;
char hej;
int i=0, k=0;
char maj[1000];
map<char, int> counter;
while(getline(cin,s))
{
for(int l=0; l<s.length();l++)
{
if(s[l]!=' ')
{
hej=s[l];
counter[hej]++;
}
}
for(map<char, int>::const_iterator memo = counter.begin(); memo!=counter.end(); memo++)
{
if(memo->second > k)
{
i=0;
k = memo -> second;
maj[i]= memo->first;
}
else if(memo->second == k)
{
i++;
maj[i]= memo->first;
}
}
for(int j=0; j<=i; j++)
{
cout<<maj[j];
}
cout<<" "<<k<<endl;
k=0;
counter.erase(counter.begin(), counter.end());
}
return 0;
}
About 499
why WA ????
SOME ONE PLEASE HELP!
SOME ONE PLEASE HELP!
Code: Select all
#include<stdio.h>
int main(){
char c;
int my[52]={0},i,max;
while(scanf("%c",&c)!=EOF){
if(c!='\n'){
if(c>=65 && c<=90){
my[c-65]++;
}
else if(c>=97 && c<=122){
my[c-97+26]++;
}
}
if(c=='\n'){
max=0;
for(i=0;i<26;i++){
if(my[i]>=my[i+26]){
my[i]+=my[i+26];
if(max<my[i]){
max=my[i];
}
my[i+26]=0;
}
else{
my[i+26]+=my[i];
if(max<my[i+26]){
max=my[i+26];
}
my[i]=0;
}
}
for(i=0;i<52;i++){
if(my[i]==max){
if(i<26){
printf("%c",i+65);
}
else{
printf("%c",i+97-26);
}
}
my[i]=0;
}
printf(" %d",max);
printf("\n");
} //newline;
} //while
return 0;
}
-
- New poster
- Posts: 19
- Joined: Sat Mar 12, 2005 5:56 pm
- Location: Halifax, Nova Scotia, Canada
- Contact:
I replaced this part of your code
with:
And got AC.
Upper case letters are supposed to be different letters from their relative lower case ones.
Code: Select all
for(i=0;i<26;i++){
if(my[i]>=my[i+26]){
my[i]+=my[i+26];
if(max<my[i]){
max=my[i];
}
my[i+26]=0;
}
else{
my[i+26]+=my[i];
if(max<my[i+26]){
max=my[i+26];
}
my[i]=0;
}
Code: Select all
max=0;
for(i=0;i<52;i++)
if(my[i]>max)
max=my[i];
Upper case letters are supposed to be different letters from their relative lower case ones.
499-PLS help
i dont understantd why my code outputs somethin strange for inputin 1st samp in. for 1st time. but when 2nd time i input somethin it outputs correctly. some 1 pls explain me whats wrong ?
#include<stdio.h>
int main(void)
{
char a[200],str[200],max;
int i,j,k;
while(gets(str)!=NULL){
max=0;
for(i='a';i<='z';i++) a=0;
for(i='A';i<='Z';i++) a=0;
for(i=0;str!='\0';i++){
if(a[str]==0){
for(j=i;str[j]!='\0';j++) if(str==str[j]) a[str]++;
if(a[str]>max) max=a[str];
}
}
for(i='A';i<='Z';i++) if(a==max) printf("%c",i);
for(i='a';i<='z';i++) if(a==max) printf("%c",i);
printf (" %d",max);
printf("\n");
}
return 0;
}
#include<stdio.h>
int main(void)
{
char a[200],str[200],max;
int i,j,k;
while(gets(str)!=NULL){
max=0;
for(i='a';i<='z';i++) a=0;
for(i='A';i<='Z';i++) a=0;
for(i=0;str!='\0';i++){
if(a[str]==0){
for(j=i;str[j]!='\0';j++) if(str==str[j]) a[str]++;
if(a[str]>max) max=a[str];
}
}
for(i='A';i<='Z';i++) if(a==max) printf("%c",i);
for(i='a';i<='z';i++) if(a==max) printf("%c",i);
printf (" %d",max);
printf("\n");
}
return 0;
}
aaa
-
- New poster
- Posts: 5
- Joined: Tue Jun 28, 2005 3:50 am
- Location: Bangladesh
- Contact:
Before opening a new thread. pls look for what you are looking for.
visit this link bellow you will be benefited.
http://online-judge.uva.es/board/viewtopic.php?t=2712
for input
my accepted code prints
hope this will help you & like to hear you from soon that you got accepted.
visit this link bellow you will be benefited.
http://online-judge.uva.es/board/viewtopic.php?t=2712
for input
Code: Select all
When riding your bicycle backwards down a one-way street, if the
wheel falls of a canoe, how many ball bearings does it take to fill
up a water buffalo?
Hello Howard.
Hello Howard.
(this is a blank line)
-------( - are spaces only)
~!@#$%^&*()_+{}:"<>?`1234567890-=[];',./
Code: Select all
e 6
al 7
a 3
Hlo 2
Hlo 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
Did you consider this???If there are are several letters that have the highest frequency u should print all of them alphabetically.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 1
- Joined: Fri Sep 16, 2005 6:08 am
499 - Argggg, help pls
i tryed most of the inputs in other msgs and got WA
here is my code...
can pls someone help me? i know its a silly problem, but i cant get AC =////

here is my code...
Code: Select all
#include <iostream.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
int main() {
int tamanho = 0;
int i = 0;
int aux1;
char aux2;
int j=0;
int maior=0;
char *linha = new char [4000];;
char letras[300];
int quantidade[300];
int indice=0;
strcpy(linha,"");
bool teste = false;
while (gets(linha)) {
for(i=0; i<300; i++) {
quantidade[i] = 0;
}
tamanho = strlen(linha);
indice = 0;
maior = 0;
for (i=0; i<tamanho; i++) {
teste = false;
for(j=0; j<indice; j++) {
if (linha[i] == letras[j]) {
quantidade[j]++;
teste = true;
}
}
if (!teste) {
if (isalpha(linha[i])!=0) {
letras[indice] = linha[i];
quantidade[indice] = 1;
indice++;
}
}
}
if (indice > 0) {
for(i=0; i<(indice-1); i++) {
for(j=(indice-1); j>1; j--) {
if (letras[j-1] > letras[j]) {
aux2 = letras[j-1];
aux1 = quantidade[j-1];
letras[j-1] = letras[j];
quantidade[j-1] = quantidade[j];
letras[j] = aux2;
quantidade[j] = aux1;
}
}
}
for(i=0; i<indice; i++) {
if (quantidade[i]>quantidade[maior]) {
maior = i;
}
}
maior = quantidade[maior];
for (i=0; i<indice; i++) {
if (quantidade[i] == maior) {
cout<<letras[i];
}
}
cout<<" "<<maior<<endl;
}
else {
cout<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0 "<<endl;
}
}
return 0;
}
^^^ map is sorterd by default 
hey man in your check you are using
what about , . and other special characters? do an isChar check and try submitting your solution
e.g
you dont want that comma there now do you 

hey man in your check you are using
Code: Select all
if(s[l]!=' ')

Code: Select all
When riding your bicycle backwards down a one-way street, if the
wheel falls of a canoe, how many ball bearings does it take to fill
up a water buffalo?
Hello Howard.
this, is, abso, lutely, crazy, dude.
Code: Select all
e 6
al 7
a 3
Hlo 2
, 5

The problem states
Output:
But your code returns...
Hope it works.
Input:The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.
Code: Select all
bbaa
Code: Select all
ab 2
Code: Select all
ba 2
Ami ekhono shopno dekhi...
HomePage
HomePage
im getting wrong answer(but its working for the input given with the problem)
plz help where am i wrong....
Code: Select all
#include<stdio.h>
int count[51];
void _initialize()
{
int i;
for(i=0;i<52;i++)
count[i]=0;
}
int main(void)
{
char ch,line[100];
int i,j,max=0;
while(1)
{
ch=getchar();
if(ch>=65 && ch<=90)
{
count[ch-65]++;
}
if(ch>=97 && ch<=122)
{
count[ch-71]++;
}
if(ch=='\n')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
max=0;
_initialize();
}
if(ch=='.')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
break;
}
}
return 0;
}
499 freq.. WA (getting output on my system though..)
help me plz...
for the inputs supplied with the problem it works dunno why im getting WA
looks big but isnt that complicated....
im getting WA .. plz help...
for the inputs supplied with the problem it works dunno why im getting WA
Code: Select all
#include<stdio.h>
int count[51];
void _initialize()
{
int i;
for(i=0;i<52;i++)
count[i]=0;
}
int main(void)
{
char ch,line[100];
int i,j,max=0;
while(1)
{
ch=getchar();
if(ch>=65 && ch<=90)
{
count[ch-65]++;
}
if(ch>=97 && ch<=122)
{
count[ch-71]++;
}
if(ch=='\n')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
max=0;
_initialize();
}
if(ch=='.')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
break;
}
}
return 0;
}
im getting WA .. plz help...