Page 4 of 16

Posted: Thu Jul 31, 2003 2:24 pm
by Zhao Le
Because there should no blank line in the last output.

10062

Posted: Sat Nov 22, 2003 7:40 am
by r.z.
what's wrong with my code?

[c]
#include<stdio.h>


void main()
{
int f[256];
char line[1001];
int i,min,idx;
int ctr;


/*
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
*/

while(gets(line)!=NULL)
{

for(i=0;i<256;i++)
{
f=0;
}

for(i=0;line!='\0';i++)
{
f[line]++;
}

do{
ctr=0;
min=255;
for(i=32;i<128;i++)
{
if(f!=0 && f<=min)
{
min=f;
idx=i;
ctr++;
}
}
if(!ctr)
break;
printf("%d %d\n",idx,min);
f[idx]=0;

}while(1);
printf("\n");
}

/*
fcloseall();
*/


}
[/c]

I've tested it and it's seems fine to me....

any critical input?

Posted: Wed Jan 07, 2004 7:28 pm
by noren
arc16: are you sure about the range 33-128?
The given lines will contain none of the first 32 or last 128 ASCII characters
/johan

10062 Why wrong answer?

Posted: Tue Feb 10, 2004 2:03 pm
by Kamanashish
I got wrong answer. Can somebody check my code.

[cpp]
The code is removed.
[/cpp]

10062 - Tell me the frequences

Posted: Fri Feb 20, 2004 6:10 pm
by Tomislav Novak
Hi.

Here is the code I keep getting WA for:
[c]
#include <stdio.h>

int main()
{
char line[1001];
int freq[96], i, j, max;

while(fgets(line, 1000, stdin))
{
line[strlen(line) - 1] = '\0';
max = 0;
memset(freq, 0, sizeof(freq));

for (i = 0; i < strlen(line); i++)
{
if (line >= 32 && line < 128)
{
freq[line - 32]++;
if (freq[line - 32] > max) max = freq[line - 32];
}
}

for (i = 1; i <= max; i++)
for (j = 96; j >= 0; j--)
if (freq[j] == i) printf("%d %d\n", j + 32, i);

printf("\n");
}

return 0;
}
[/c]

Can anyone tell me where the mistake is, or at least give me some more test data?

Thanks.

Re: 10062 - Tell me the frequences

Posted: Fri Feb 20, 2004 7:34 pm
by little joey
[quote="Tomislav Novak"]Hi.

Here is the code I keep getting WA for:
[c]
#include <stdio.h>

int main()
{
char line[1001];
// make it a little bigger, 1024 will do

int freq[96], i, j, max;

Posted: Mon Mar 01, 2004 4:03 pm
by A1
I have give this input in your program:

AAAAAAAAABBBBBBBBBBBBCCCDDDDDDEEEEEEEEFFFFFFaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrr

and it give output:

67 3
114 6
70 6
97 8
69 8
65 9
66 12
68 26

you see here 114(r) is 6 and 68(D) is 26

but output should be 68 6 and 114 26

try to overcome this problam. :)

note:you don't need to declare c[1001] two time. just remove the first declaration.

Posted: Thu Mar 04, 2004 10:55 am
by A1
when i compile your code using g++ compiler it give this message:

" the `gets' function is dangerous and should not be used."

But I think it should not be a reason for WA.
for all input (i test) your code gives same output as my AC code give. :-?
there may be some lack in gets function.
I solve it using getchar();
So, try again :wink:

10062 > Tell me the frequencies! > Code changed.

Posted: Tue Apr 13, 2004 3:20 am
by _.B._
Greetings!.
Can anyone PLEASE tell me why I got "Runtime Error (SIGSEGV)" in this problem?? :o

The limits for the "ordinal" of the characters read are 33 to 127??. No character read, except for eoLn and eoF, will be out of those limits??.
since there is a Max = 1000 for the characters in a line, the maximum value for a char will be 1000, rite??.
Thanks in advance.

The message on my e-mail is:
Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

Before crash, it ran during 0.045 seconds.
My code:
[pascal]{ Bernardo E. L

Posted: Wed Apr 14, 2004 2:30 pm
by WR
Your sample output is ok.

Perhaps you should change the limit for valid data to 256.

Posted: Wed Apr 14, 2004 9:24 pm
by _.B._
Hello again WR!.
Thanks for the tip, but nada :o
Changed the code again.
I hate this... it was supposed to be a simple code...
Thanks, one more time.
Keep posting!.

Posted: Fri Apr 16, 2004 8:02 am
by WR
What about blanks (ASCII 32)??!!

OUCH!.

Posted: Sat Apr 17, 2004 12:16 am
by _.B._
WR wrote:What about blanks (ASCII 32)??!!
OUCH!.
Seems to be that I forgot how to substract :o
Thanks again WR!.
Got AC/PE. Will check for the PE now.
Keep posting!, and I'll re-study mathe basics :lol:

10062 tell me frequences!!!! WA 10062

Posted: Fri Apr 23, 2004 2:54 pm
by Pavl0
hello
why j get wa ??


#include<stdio.h>

char stat [512];

void pw(void)
{
int i,j;

for(i=1;i!=1024;i++)
{
j=500;
while(j--)
{
if(stat[j]==i)printf("%d %d\n",j,stat[j]);
}

}

}

main()
{
int i;
char ch;

while(1)
{
ch=getchar();
if(ch=='\n'|| ch=='\r'){pw(); for(i=0;i!=512;i++)stat=0; printf("\n");}
else stat[ch]++;
if(ch==EOF){pw(); break;}



}



}

Posted: Tue Apr 27, 2004 4:35 am
by dark man
you have to give a blank line after each set of output but not after the last set.May be this will make your code AC.