## 10062 - Tell me the frequencies!

Moderator: Board moderators

Learning poster
Posts: 57
Joined: Sun Sep 29, 2002 12:00 pm
Location: in front of the monitor :-)
Contact:
hello. i think you need to look into your sorting process more closely.[/code]

JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am
Thank you, I will check it more closely and post a new result.

Angel
New poster
Posts: 8
Joined: Wed Nov 20, 2002 3:49 pm

### 10062WA : why ???

This is my code ..... i dunno why wrong ans ..... what's wrong here ????
plz help me ....

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

char A[1010],B[1010],ch;
int intB[1010],intC[1010];

void main(void)
{
int c,i,j,k,len,f;
while(gets(A))
{
len=strlen(A);
strcpy(B,A);
k=0;c=0;f=1;ch=0;
for(i=0;i<1010;i++)intC=0;
for(i=0;i<1010;i++)intB=0;

for(i=0;i<len;i++)
{
if(f==1)
{
for(j=i;j<len;j++)
{
if(A==B[j])
{
intC[c]++;
ch=A;
B[j]=0;
f=0;
}
else
{
c++;i=j-1;
intB[k++]=ch;
f=1;
break;
}
/*if(f==0)
{
i=j-1;
f=0;
}
else f=0; */
}
}
}
intB[k++]=ch;
for(i=0;intC;i++)
{
for(j=i+1;intC[j];j++)
{
if(intC>intC[j] || (intC==intC[j] && intB<intB[j]))
{
intC^=intC[j]^=intC^=intC[j];
intB[i]^=intB[j]^=intB[i]^=intB[j];
}
}
}
for(i=0;intC[i];i++)printf("%d %d\n",intB[i],intC[i]);
printf("\n");
}
}

this is my code ..

mafattah
New poster
Posts: 23
Joined: Fri Apr 26, 2002 1:00 am
Location: Cairo, Egypt

### 10062 - Tell me the frequencies

I know the code is badly written, but I cannot find the input set that cracked it. It gives WA. I tried a lot of weird input, but could not get unexpected results.
[cpp]#include <iostream.h>
#include <string.h>

void main() {
char temp[2000];
int freq[129];
int i;
bool firsttime = true;
cin.getline(temp, 2000);
while (1) {
if (!firsttime) cout << endl;
firsttime = false;
for (i = 0; i < 129; i++) freq = 0;
for (i = 0; temp; i++) {
freq[int(temp)]++;
}
int minfreq;
minfreq = 10000;
for (i = 0; i < 129; i++) if (freq < minfreq && freq != 0) minfreq = freq;
while (minfreq < 9999) {
for (i = 127; i >= 32; i--) {
if (freq == minfreq) {
cout << i << " " << freq << endl;
freq = 10000;
}
}
minfreq = 10000;
for (i = 0; i < 129; i++) if (freq < minfreq && freq[i] != 0) minfreq = freq[i];
}
cin.getline(temp, 2000);
char ch;
cin.get(ch);
if (!cin.eof()) cin.putback(ch); else break;
}
}[/cpp]

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
One problem i found is

if the input is
AAABBC
AAABBC

the output comes for the first time,
but for the second case there is no output.
Try correcting this.

mafattah
New poster
Posts: 23
Joined: Fri Apr 26, 2002 1:00 am
Location: Cairo, Egypt
Thank you for the reply. I tried it and it works with me. It will work with you if you put the input that is after it, or if it is at the end of file, which should be good enough for the judge.

Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

### 10062 - Tell me the frequencies WA?

[c]
#include<stdio.h>
#include<string.h>

int l,stat[200],m,i,j,n,num[1010],sum[1010],t;
char a[1050];

void main(){
while(gets(a)){

l=strlen(a);

for(i=0;i<l;i++) stat[a]++;

for(i=33,n=0;i<129;i++){
if(stat){
num[n]=i;
sum[n]=stat;
stat=0;
n++;
}
}

//Sorting part
for(i=0,m=n-1;i<m;i++){
t=i;
for(j=i+1;j<n;j++){
if(sum[j]<=sum[t]){
if(sum[j]==sum[t]){
if(num[t]<num[j]) t=j;
}
else t=j;
}
}
if(t!=i){
l=num[t];num[t]=num;num=l;
l=sum[t];sum[t]=sum;sum=l;
}
}

//Printing part
for(i=0;i<n;i++) printf("%i %i\n",num,sum);
printf("\n");
}
}
[/c]
Can anybody tell me where my mistake is?

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut
consider the following part:

Code: Select all

``````for(i=0;i<l;i++) stat[a[i]]++;
``````
you've made increment for variable stat, but you didnt initialize the variable first. try to initialize first.

titid gede
Kalo mau kaya, buat apa sekolah?

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
The problem statement says:
The given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with ‘\n’ and ‘\r’ but always keep those out of consideration.
This means that the character having ASCII value of 128 can also be part of the input file. Your program is unable to handle it.

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut
i dont think there will be ASCII char 128, since ASCII char are number from 0-255. then maximum ASCII char that could be exist is 127. tell me if i am wrong.

titid gede
Kalo mau kaya, buat apa sekolah?

Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia
For titid_gede, I've tried to intialize :
[c]
for(i=0;i<200;i++) stat=0;
[/c]
I put that line between void main(){ and while(gets(a)){ but still WA.
And for shamim, I dunno the maximum ASCII value (255 or 256), so just in case, in the program I use:
[c]
for(i=33,n=0;i<129;i++)
[/c]
So the value of i can reach 128.
Still WA, though. Help plz.
Thanks

Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia
Apparently, the ASCII value range is from 0 - 255 like titid_gede said. This would mean the first 32 ASCII would be from 0-31 and the last 128 ASCII would be 128-255.
In that case I just change the line
[c]
for(i=33,n=0;i<128;i++)
[/c]

with
[c]
for(i=32,n=0;i<128;i++)
[/c]

And now Got it ACC, but with PE. Oh well, that's better than WA anyway.
Thanks for the help guys !!

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

### 10062

I don't understand, why I got the 10008 AC

but the similar 10062 WA.

[cpp]#include <iostream>

using namespace std;

int const Max=1000;

void Output(int T[],int cnt,int position)
{
int i;
for(i=position;i>=0;i--)
if(T==cnt) cout<<i<<' '<<T<<endl;
}

void main()
{
char S[Max]={NULL};
while(cin.getline(S,Max))
{
int T[128]={0}; // to store the number of freqency
int length=cin.gcount()-1;
int i=0;
while(S)
{
T[int(S)]++;
i++;
}
int cnt=Max,position;
for(i=127;i>=0;i--)
if(T&&T<cnt)
{
cnt=T; // find the smallest one in the alphabet & position
position=i;
}
while(cnt<=1000)
{
Output(T,cnt,position);
position=127;
cnt++;
}
cout<<endl;
}
}[/cpp]
AC makes me feels good,
But WA makes me thinks hard.

Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia
// find the smallest one in the alphabet & position
I think the problem clearly states that if there are two characters appear at the same time, the one with higher ASCII Value must appear first.

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China
Well, because of my code is just change from 10008
so don't mention the line after //

I got ACC now.
Thanks
AC makes me feels good,
But WA makes me thinks hard.