Page 3 of 16
Posted: Tue May 06, 2003 7:07 pm
by Adil
hello. i think you need to look into your sorting process more closely.[/code]
Posted: Tue May 06, 2003 7:17 pm
by JiaYun
Thank you, I will check it more closely and post a new result.

10062WA : why ???
Posted: Wed May 21, 2003 7:05 pm
by Angel
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 ..
10062 - Tell me the frequencies
Posted: Thu Jun 12, 2003 10:32 am
by mafattah
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]
Posted: Sun Jun 15, 2003 8:29 am
by shamim
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.
Posted: Wed Jun 18, 2003 6:53 pm
by mafattah
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.
10062 - Tell me the frequencies WA?
Posted: Mon Jul 28, 2003 11:32 am
by Joseph Kurniawan
[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?
Thanks in advance!
Posted: Mon Jul 28, 2003 12:34 pm
by titid_gede
consider the following part:
you've made increment for variable stat, but you didnt initialize the variable first. try to initialize first.
titid gede
Posted: Mon Jul 28, 2003 12:43 pm
by shamim
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.
Posted: Mon Jul 28, 2003 1:00 pm
by titid_gede
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
Posted: Tue Jul 29, 2003 4:41 am
by Joseph Kurniawan
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
Posted: Tue Jul 29, 2003 5:58 am
by Joseph Kurniawan
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 !!

10062
Posted: Thu Jul 31, 2003 9:51 am
by Zhao Le
I don't understand, why I got the 10008 AC
but the similar 10062 WA.
Please help or give the test case.
Thanks in advance.
[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]
Posted: Thu Jul 31, 2003 11:03 am
by Joseph Kurniawan
// 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.
Posted: Thu Jul 31, 2003 2:01 pm
by Zhao Le
Well, because of my code is just change from 10008
so don't mention the line after //
I got ACC now.
Thanks