10062 - Tell me the frequencies!
Moderator: Board moderators
10062 -- WA
I tried hundreds of times but still got WA in 10062,can u help me to check my code?
[cpp]#include <iostream.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char a[1024];
int len,i,str[2][256]={0,0},n,min=1000,temp,k,flag=0;
while(gets(a)!=NULL)
{
len=strlen(a);
for(i=0;i<len;i++)
{
n=a;
str[0][n]=n;
str[1][n]++;
}
for(k=0;k<129;k++)
{
for(i=32;i<128;i++)
{
if(str[1]<min&&str[1]!=0) {min=str[1];temp=i;flag=1;}
}
if(flag==1)
{
cout<<str[0][temp]<<" "<<str[1][temp]<<endl;
str[1][temp]=0;
min=1000;
flag=0;
}
}
cout<<endl;
}
return 0;
}[/cpp]
thx a lot ~~
[cpp]#include <iostream.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char a[1024];
int len,i,str[2][256]={0,0},n,min=1000,temp,k,flag=0;
while(gets(a)!=NULL)
{
len=strlen(a);
for(i=0;i<len;i++)
{
n=a;
str[0][n]=n;
str[1][n]++;
}
for(k=0;k<129;k++)
{
for(i=32;i<128;i++)
{
if(str[1]<min&&str[1]!=0) {min=str[1];temp=i;flag=1;}
}
if(flag==1)
{
cout<<str[0][temp]<<" "<<str[1][temp]<<endl;
str[1][temp]=0;
min=1000;
flag=0;
}
}
cout<<endl;
}
return 0;
}[/cpp]
thx a lot ~~
-
- New poster
- Posts: 13
- Joined: Tue Aug 03, 2004 4:24 am
- Location: CHINA
10062 help me
When I submit ,I select the Language is C,the judge is
Compile Error,then I select the Language is C++,and the judge is Wrong Answer,who can help me,Thank you in advance!
[c]# include <stdio.h>
# include <string.h>
struct node
{
char ch;
int fre;
};
int main()
{
char str[1000];
node nod[1000],temp;
int i,j,k,m,n,len,pos,start,end;
while(scanf("%s",str)!=EOF)
{
k=0;
len=strlen(str);
for(i=0;i<len;i++)
{
pos=0;
nod.fre=0;
for(j=0;j<k;j++)
{
if(nod[j].ch==str)
{
nod[j].fre++;
pos=1;
break;
}
}
if(pos==0)
{
nod[k++].ch=str;
nod[k-1].fre=1;
}
}
for(i=1;i<k;i++)
for(j=0;j<k-i;j++)
{
if(nod[j].fre>nod[j+1].fre)
{
temp=nod[j];
nod[j]=nod[j+1];
nod[j+1]=temp;
}
}
for(i=nod[0].fre;i<=nod[k-1].fre;i++)
{
end=0;
for(j=0;j<k;j++)
if(nod[j].fre==i)
{
if(end==0)
{
start=j;
end++;
}
else
end++;
}
if(end>1)
{
for(m=1;m<end;m++)
for(n=start;n<start+end-m;n++)
{
if(nod[n].ch<nod[n+1].ch)
{
temp=nod[n];
nod[n]=nod[n+1];
nod[n+1]=temp;
}
}
}
}
for(j=0;j<k;j++)
printf("%d %d\n",nod[j].ch,nod[j].fre);
printf("\n");
}
return 0;
}
[/c]
Compile Error,then I select the Language is C++,and the judge is Wrong Answer,who can help me,Thank you in advance!
[c]# include <stdio.h>
# include <string.h>
struct node
{
char ch;
int fre;
};
int main()
{
char str[1000];
node nod[1000],temp;
int i,j,k,m,n,len,pos,start,end;
while(scanf("%s",str)!=EOF)
{
k=0;
len=strlen(str);
for(i=0;i<len;i++)
{
pos=0;
nod.fre=0;
for(j=0;j<k;j++)
{
if(nod[j].ch==str)
{
nod[j].fre++;
pos=1;
break;
}
}
if(pos==0)
{
nod[k++].ch=str;
nod[k-1].fre=1;
}
}
for(i=1;i<k;i++)
for(j=0;j<k-i;j++)
{
if(nod[j].fre>nod[j+1].fre)
{
temp=nod[j];
nod[j]=nod[j+1];
nod[j+1]=temp;
}
}
for(i=nod[0].fre;i<=nod[k-1].fre;i++)
{
end=0;
for(j=0;j<k;j++)
if(nod[j].fre==i)
{
if(end==0)
{
start=j;
end++;
}
else
end++;
}
if(end>1)
{
for(m=1;m<end;m++)
for(n=start;n<start+end-m;n++)
{
if(nod[n].ch<nod[n+1].ch)
{
temp=nod[n];
nod[n]=nod[n+1];
nod[n+1]=temp;
}
}
}
}
for(j=0;j<k;j++)
printf("%d %d\n",nod[j].ch,nod[j].fre);
printf("\n");
}
return 0;
}
[/c]
-
- New poster
- Posts: 13
- Joined: Tue Aug 03, 2004 4:24 am
- Location: CHINA
example
I test many cases,the result is right.
example
input:
ABCCDDEEEFFF
output:
66 1
65 1
68 2
67 2
70 3
69 3
why WA?
example
input:
ABCCDDEEEFFF
output:
66 1
65 1
68 2
67 2
70 3
69 3
why WA?
-
- New poster
- Posts: 13
- Joined: Tue Aug 03, 2004 4:24 am
- Location: CHINA
Thanks
who can give me some test cases?
help help!!
help help!!
10062 WA
Can anybody help me? I have WA with this code
[c]
#include <stdio.h>
#include <string.h>
int main (void){
int m[1500], i, len, count=1, max=0, njulajn=0;
char s[1500];
while (!feof(stdin)){
njulajn++;
if (njulajn>1)
printf ("\n");
memset (m, 0, sizeof(m));
gets(s);
len=strlen(s);
for (i=0; i<len; i++)
m[s]++;
for (i=0; i<255; i++){
if (m>max)
max=m;
}
while (count<=max){
for (i=255; i>0; i--){
if (m==count)
printf ("%d %d\n", i, count);
}
count++;
}
max=0;
count=1;
len=0;
}
return 0;
}
[/c]
![:-?](./images/smilies/icon_confused.gif)
[c]
#include <stdio.h>
#include <string.h>
int main (void){
int m[1500], i, len, count=1, max=0, njulajn=0;
char s[1500];
while (!feof(stdin)){
njulajn++;
if (njulajn>1)
printf ("\n");
memset (m, 0, sizeof(m));
gets(s);
len=strlen(s);
for (i=0; i<len; i++)
m[s]++;
for (i=0; i<255; i++){
if (m>max)
max=m;
}
while (count<=max){
for (i=255; i>0; i--){
if (m==count)
printf ("%d %d\n", i, count);
}
count++;
}
max=0;
count=1;
len=0;
}
return 0;
}
[/c]
10062 why w.A
Why This Got Wa? Plzz Help. Give Some Critical I/O
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct FREQUENCY
{
int ascii;
long count;
}freq[1000];
char ch[1000];
void Sort(int n)
{
struct FREQUENCY temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(freq[j].count<freq.count)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
else if(freq[j].count==freq.count)
{
if(freq[j].ascii>freq.ascii)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
}
}
}
void main()
{
clrscr();
int ln=0,i=0,mutex,l=0;
freopen("c:\\in.txt","r",stdin);
while(gets(ch))
{
l=0;
if(ln!=0)
printf("\n\n");
ln=strlen(ch);
if(ln>1000)
break;
i=0;
for(int k=0;k<ln;k++)
{
mutex=0;
if((int)ch[k]>32&&(int)ch[k]<=128)
{
for(i=0;i<k;i++)
{
if(freq.ascii==(int)ch[k])
{
freq.count++;
mutex=1;
}
}
if(!mutex)
{
freq[l].ascii=(int)ch[k];
freq[l].count=1;
l++;
}
}
}
Sort(l);
for(int j=0;j<l;j++)
printf("%d %ld%s",freq[j].ascii,freq[j].count,(j<l-1)?"\n":"");
}
}
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct FREQUENCY
{
int ascii;
long count;
}freq[1000];
char ch[1000];
void Sort(int n)
{
struct FREQUENCY temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(freq[j].count<freq.count)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
else if(freq[j].count==freq.count)
{
if(freq[j].ascii>freq.ascii)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
}
}
}
void main()
{
clrscr();
int ln=0,i=0,mutex,l=0;
freopen("c:\\in.txt","r",stdin);
while(gets(ch))
{
l=0;
if(ln!=0)
printf("\n\n");
ln=strlen(ch);
if(ln>1000)
break;
i=0;
for(int k=0;k<ln;k++)
{
mutex=0;
if((int)ch[k]>32&&(int)ch[k]<=128)
{
for(i=0;i<k;i++)
{
if(freq.ascii==(int)ch[k])
{
freq.count++;
mutex=1;
}
}
if(!mutex)
{
freq[l].ascii=(int)ch[k];
freq[l].count=1;
l++;
}
}
}
Sort(l);
for(int j=0;j<l;j++)
printf("%d %ld%s",freq[j].ascii,freq[j].count,(j<l-1)?"\n":"");
}
}
/*I have changed my code but still W.A. Please Help*/
/* Here is my changed code*/
#include<stdio.h>
#include<string.h>
struct FREQUENCY
{
int ascii;
long count;
}freq[1000];
char ch[1000];
void Sort(int n)
{
struct FREQUENCY temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(freq[j].count<freq.count)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
else if(freq[j].count==freq.count)
{
if(freq[j].ascii>freq.ascii)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
}
}
}
void main()
{
int ln=0,i=0,mutex,l=0;
while(gets(ch))
{
l=0;
if(ln!=0)
printf("\n\n");
ln=strlen(ch);
if(ln>1000)
break;
i=0;
for(int k=0;k<ln;k++)
{
mutex=0;
if((int)ch[k]>32&&(int)ch[k]<=128)
{
for(i=0;i<k;i++)
{
if(freq.ascii==(int)ch[k])
{
freq.count++;
mutex=1;
}
}
if(!mutex)
{
freq[l].ascii=(int)ch[k];
freq[l].count=1;
l++;
}
}
}
Sort(l);
for(int j=0;j<l;j++)
{
printf("%d %ld%s",freq[j].ascii,freq[j].count,(j<l-1)?"\n":"");
freq[j].ascii=0;
freq[j].count=0;
}
}
}
/* Here is my changed code*/
#include<stdio.h>
#include<string.h>
struct FREQUENCY
{
int ascii;
long count;
}freq[1000];
char ch[1000];
void Sort(int n)
{
struct FREQUENCY temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(freq[j].count<freq.count)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
else if(freq[j].count==freq.count)
{
if(freq[j].ascii>freq.ascii)
{
temp=freq;
freq=freq[j];
freq[j]=temp;
}
}
}
}
void main()
{
int ln=0,i=0,mutex,l=0;
while(gets(ch))
{
l=0;
if(ln!=0)
printf("\n\n");
ln=strlen(ch);
if(ln>1000)
break;
i=0;
for(int k=0;k<ln;k++)
{
mutex=0;
if((int)ch[k]>32&&(int)ch[k]<=128)
{
for(i=0;i<k;i++)
{
if(freq.ascii==(int)ch[k])
{
freq.count++;
mutex=1;
}
}
if(!mutex)
{
freq[l].ascii=(int)ch[k];
freq[l].count=1;
l++;
}
}
}
Sort(l);
for(int j=0;j<l;j++)
{
printf("%d %ld%s",freq[j].ascii,freq[j].count,(j<l-1)?"\n":"");
freq[j].ascii=0;
freq[j].count=0;
}
}
}
-
- New poster
- Posts: 32
- Joined: Fri Oct 01, 2004 10:53 pm
10062 Please Help
for my IO
do i make it...
<start>
AAABBC<input1>
<blank line>
67 1
66 2
65 3<outputs1>
122333<input1>
<blank line>
49 1
50 2
51 3<outputs1>
<end>
or is this formatting wrong
might as well check my code...
[java]import java.io.IOException;
import java.util.StringTokenizer;
class Main
{
int[] cc = new int[128];
String ReadLn()
{
int car=-1;
try
{
while(true)
{
car=System.in.read();
if ((car<0)||(car=='\n'))
break;
else if(car>32&&car<128)
cc[car]++;
}
}
catch(IOException e){}
if(car<0)
return(null);
return("");
}
public static void main(String[] args)
{
Main newMain = new Main();
newMain.start();
}
void start()
{
String input;
int min,min_i,i;
while ((input=ReadLn())!=null)
{
System.out.println();
min = 1001;
min_i = 0;
i=-1;
while(i<127)
{
i++;
if((cc<min)&&(cc>0))
{
if(i<126)
{
min = cc;
min_i = i;
}
else
{
System.out.print(i);
System.out.println(" "+cc);
min = 1001;
cc = -1;
i = -1;
min_i = -1;
}
}
else if(i==127&&min!=1001&&min_i!=-1)
{
if(cc[min_i]>0)
{
System.out.print(min_i);
System.out.println(" "+cc[min_i]);
}
min = 1001;
cc[min_i] = -1;
min_i = -1;
i = -1;
}
}
}
}
}[/java]
do i make it...
<start>
AAABBC<input1>
<blank line>
67 1
66 2
65 3<outputs1>
122333<input1>
<blank line>
49 1
50 2
51 3<outputs1>
<end>
or is this formatting wrong
might as well check my code...
[java]import java.io.IOException;
import java.util.StringTokenizer;
class Main
{
int[] cc = new int[128];
String ReadLn()
{
int car=-1;
try
{
while(true)
{
car=System.in.read();
if ((car<0)||(car=='\n'))
break;
else if(car>32&&car<128)
cc[car]++;
}
}
catch(IOException e){}
if(car<0)
return(null);
return("");
}
public static void main(String[] args)
{
Main newMain = new Main();
newMain.start();
}
void start()
{
String input;
int min,min_i,i;
while ((input=ReadLn())!=null)
{
System.out.println();
min = 1001;
min_i = 0;
i=-1;
while(i<127)
{
i++;
if((cc<min)&&(cc>0))
{
if(i<126)
{
min = cc;
min_i = i;
}
else
{
System.out.print(i);
System.out.println(" "+cc);
min = 1001;
cc = -1;
i = -1;
min_i = -1;
}
}
else if(i==127&&min!=1001&&min_i!=-1)
{
if(cc[min_i]>0)
{
System.out.print(min_i);
System.out.println(" "+cc[min_i]);
}
min = 1001;
cc[min_i] = -1;
min_i = -1;
i = -1;
}
}
}
}
}[/java]
10062 why Runtime Error (SIGSEGV)andWA
#include <stdio.h>
void main(void)
{
int c,k=0,i,b,j,l,m;
int a[90][1000][2];
for(j=0;j<90;++j){
for(i=0; i<1000; ++i){
a[j][0]=0;
a[j][1]=0;
}
}
l=0;
while((c = getchar()) !=EOF){
if(c=='\n'){
a[l][k][0]=10;
a[l][k][1]=1001;
l++;
k=-1;
}
for(i=0;i<k;i++){
if(c==a[l][0]){
++a[l][1];
break;
}
}
if(c!=a[l][0]){
a[l][k][0]=c;
k++;
}
}
for(m=0;m<l;m++){
for(j=0;j<1000;j++){
for(i=0;a[m][0]!=10;i++){
if(a[m][1]>a[m][i+1][1]){
b=a[m][1];
a[m][1]=a[m][i+1][1];
a[m][i+1][1]=b;
}
else if(a[m][1]==a[m][i+1][1]){
if(a[m][i][0]<a[m][i+1][0]){
b=a[m][i][0];
a[m][i][0]=a[m][i+1][0];
a[m][i+1][0]=b;
}
}
}
}
}
for(m=0;m<l;m++){
for(i=0;a[m][i][0]!=10;i++){
printf("%d %d\n",a[m][i][0],(a[m][i][1]+1));
}
printf("\n");
}
}
void main(void)
{
int c,k=0,i,b,j,l,m;
int a[90][1000][2];
for(j=0;j<90;++j){
for(i=0; i<1000; ++i){
a[j][0]=0;
a[j][1]=0;
}
}
l=0;
while((c = getchar()) !=EOF){
if(c=='\n'){
a[l][k][0]=10;
a[l][k][1]=1001;
l++;
k=-1;
}
for(i=0;i<k;i++){
if(c==a[l][0]){
++a[l][1];
break;
}
}
if(c!=a[l][0]){
a[l][k][0]=c;
k++;
}
}
for(m=0;m<l;m++){
for(j=0;j<1000;j++){
for(i=0;a[m][0]!=10;i++){
if(a[m][1]>a[m][i+1][1]){
b=a[m][1];
a[m][1]=a[m][i+1][1];
a[m][i+1][1]=b;
}
else if(a[m][1]==a[m][i+1][1]){
if(a[m][i][0]<a[m][i+1][0]){
b=a[m][i][0];
a[m][i][0]=a[m][i+1][0];
a[m][i+1][0]=b;
}
}
}
}
}
for(m=0;m<l;m++){
for(i=0;a[m][i][0]!=10;i++){
printf("%d %d\n",a[m][i][0],(a[m][i][1]+1));
}
printf("\n");
}
}
and the second way is also WA...why??
#include <stdio.h>
void main(void)
{
int c,k=0,i,b,j;
int a[1000][2];
for(i=0; i<1000; i++){
a[0]=0;
a[1]=0;
}
while((c = getchar()) !=EOF){
for(i=0;i<k;i++){
if(c==a[0]){
++a[1];
break;
}
}
if(c!=a[0]){
a[k][0]=c;
k++;
}
if(c==10){
for(j=0;j<1000;j++){
for(i=0;i<k-2;i++){
if(a[1]>a[i+1][1]){
b=a[1];
a[1]=a[i+1][1];
a[i+1][1]=b;
}
else if(a[1]==a[i+1][1]){
if(a[0]<a[i+1][0]){
b=a[i][0];
a[i][0]=a[i+1][0];
a[i+1][0]=b;
}
}
}
}
for(i=0;i<k-1;i++){
printf("%d %d\n",a[i][0],(a[i][1]+1));
}
printf("\n");
for(i=0; i<1000; i++){
a[i][0]=0;
a[i][1]=0;
}
k=0;
}
}
}
void main(void)
{
int c,k=0,i,b,j;
int a[1000][2];
for(i=0; i<1000; i++){
a[0]=0;
a[1]=0;
}
while((c = getchar()) !=EOF){
for(i=0;i<k;i++){
if(c==a[0]){
++a[1];
break;
}
}
if(c!=a[0]){
a[k][0]=c;
k++;
}
if(c==10){
for(j=0;j<1000;j++){
for(i=0;i<k-2;i++){
if(a[1]>a[i+1][1]){
b=a[1];
a[1]=a[i+1][1];
a[i+1][1]=b;
}
else if(a[1]==a[i+1][1]){
if(a[0]<a[i+1][0]){
b=a[i][0];
a[i][0]=a[i+1][0];
a[i+1][0]=b;
}
}
}
}
for(i=0;i<k-1;i++){
printf("%d %d\n",a[i][0],(a[i][1]+1));
}
printf("\n");
for(i=0; i<1000; i++){
a[i][0]=0;
a[i][1]=0;
}
k=0;
}
}
}