10062 - Tell me the frequencies!

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

takumi
New poster
Posts: 10
Joined: Tue Dec 10, 2002 6:15 pm

Post by takumi »

uhmmmm I am really confuses now..
I chance my code a little but it still WA
do it got anything goes wrong
[c]#include <stdio.h>

int main()
{
char input[1001];
int i, temp, ascii[256];

for ( i = 0; i < 1001; i++ ) { input = NULL; }

while (gets(input) != NULL) {
for ( i= 0; i <= 256; i++ ) { ascii = 0; }

for ( i = 0; i < 1001; i++ ) {
temp = input;
ascii[temp]++;
}
if ( input[0] == input[1] && input[0] != '\0' && input[1] != '\0' ) {

for ( i = 255; i > 0; i-- ) {
if ( ascii != 0 ) { printf("%d %d\n", i, ascii ); }

}
}
else {
for ( i = 1; i < 256; i++ ) {
if ( ascii != 0 ) { printf("%d %d\n", i, ascii ); }
}
}
for ( i = 0; i <= 1001; i++ ) { input = NULL; }

}
return 0;
}[/c]
thanks for repply :)
route
New poster
Posts: 39
Joined: Sat Dec 21, 2002 1:25 am

Post by route »

a blank line after each set of output...
takumi
New poster
Posts: 10
Joined: Tue Dec 10, 2002 6:15 pm

Post by takumi »

there is some question I want to ask
1. if the linput like this:
<blank line><blank line>122333
what should the output like?

49 1
50 2
51 3

or

51 3
50 2
49 1

2. do the ascii value for all character has to be printed even 'blank line' and 'enter' char??

thank you very much..
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

ascii for enter?? I don't think you should print that. But for space you should print the value , sort them like the output description tell
amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

Please help me !!!

Post by amd-RS »

Hi all,

I don't understand why I get WA on my code:

[c]
#include <stdio.h>

void main ()
{
int i, j, c = 0, vetor[256], vetor1[256], temp1;
char str[1000], temp;

while (gets(str) != NULL)
{
for (i = 0; i < 256; i++)
{
vetor = vetor1 = 0;
}
temp1 = 0;
str[1000]='\0';

for (i = 1; str != '\0'; i++)
{
for (j = 1; str[j] != '\0'; j++)
{
if (str[j - 1] < str)
{
temp = str[j - 1];
str[j - 1] = str;
str = temp;
}
}
}
for (i = 0;str != '\0' ; i++)
{
while (str == str[i + 1])
{
c++;
i++;
}
vetor[temp1] = c + 1;
vetor1[temp1] = str;
temp1++;
c = 0;
}
for (i = 0; i < temp1; i++)
for (j = i + 1; j < temp1; j++)
{
if (vetor > vetor[j])
{
temp = vetor[i];
vetor[i] = vetor[j];
vetor[j] = temp;
temp = vetor1[i];
vetor1[i] = vetor1[j];
vetor1[j] = temp;
}
else if (vetor[i] == vetor[j]
&& vetor1[i] < vetor1[j])
{
temp = vetor1[i];
vetor1[i] = vetor1[j];
vetor1[j] = temp;
}
}


for (i = 0; i < temp1; i++)
printf ("%d %d\n", vetor1[i], vetor[i]);
if(str[0]!='\n')
printf("\n");
}
}
[/c]

Please, help me, I'm going nut. I spent over a week at this problem :(
amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

10062

Post by amd-RS »

Hi,

First of all, I think you should do ascii check conditon ...

Good luck , Aur
WillieLi
New poster
Posts: 1
Joined: Thu Apr 03, 2003 6:10 am
Location: Texas, USA
Contact:

10062

Post by WillieLi »

this code got accepted but the online judge said it has presentation error..@@
could anyone examine the code below and tell me why??...
thanx a lot in advance...:D

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

void main()
{
int b[256],i;
char str[10000];
for(i = 0;i <= 130; i++)
{
b = 0;
}
while(gets(str))
{
int final = 0,j;
for(i = 0; i < strlen(str); i++)
{
if(str >= 32 && str <= 127)
{
b[str]++;
if(b[str] > final)
final = b[str];
else
final = final;
}
}
for(i = 1;i <= final; i++)
{
for(j = 130; j >= 0; j--)
{
if(b[j] == i)
{
printf("%d %d\n",j,i);
b[j] = 0;
}
}
}
printf("\n");
}
}
[/cpp]
User avatar
cytse
Learning poster
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong
Contact:

Post by cytse »

there should be no blank line after the last set of output
Professor_Of_Love
New poster
Posts: 9
Joined: Tue Apr 01, 2003 10:03 pm
Location: Dhaka, Bangladesh

Post by Professor_Of_Love »

I am very very disappointed with this problem... I am getting WA. But I have solved similar problem like #10008. I can't find any mistake here. Can anyone help me?? Thanks in advance!

[c]#include<stdio.h>
#include<string.h>
#define N 10000
#define M 160

struct {
char ch;
int c;
}chrs[M];

unsigned char str[N],countStruct,i,j;

int isValid(char ch)
{
if(ch>=32&&ch<=127)
return 1;
else
return 0;
}

void swap(int *i, int *j)
{
*i = *i + *j - (*j=*i);
return;
}

void swapC(char *i, char *j)
{
*i = *i + *j - (*j=*i);
return;
}

void init()
{
int i;
for(i=0;i<M;i++)
chrs.ch=0,chrs.c=0;
return;
}

void main(void)
{
while(gets(str))
{
init();
countStruct = 0;
for(i=0;i<strlen(str);i++)
{
if(isValid(str))
{
for(j=0;j<countStruct;j++)
if(chrs[j].ch==str)
{
chrs[j].c++;
break;
}
if(j>=countStruct)
countStruct++,chrs[j].c=1,chrs[j].ch=str;
}
}
for(i=0;i<countStruct-1;i++)
for(j=i+1;j<countStruct;j++)
if(chrs.c>chrs[j].c)
{
swapC(&chrs.ch,&chrs[j].ch);
swap(&chrs.c,&chrs[j].c);
}
for(i=0;i<countStruct-1;i++)
for(j=i+1;j<countStruct;j++)
if((chrs.c==chrs[j].c)&&(chrs.ch<chrs[j].ch))
swapC(&chrs[i].ch,&chrs[j].ch);
for(j=0;j<countStruct;j++)
printf("%d %d\n",chrs[j].ch,chrs[j].c);
printf("\n");
}
}[/c]
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »

in online judge forget about presentation error...
it doesn't indicate author's lagging....

---
anupam :oops: :oops: :oops:
"Everything should be made simple, but not always simpler"
Professor_Of_Love
New poster
Posts: 9
Joined: Tue Apr 01, 2003 10:03 pm
Location: Dhaka, Bangladesh

Post by Professor_Of_Love »

But, what about my WA??
JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

10062 WA

Post by JiaYun »

As comments, I hava tried several ways. But it's still WA.... :cry:

[cpp]
deleted
[/cpp]
Last edited by JiaYun on Sat Jun 19, 2004 8:16 am, edited 1 time in total.
JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

Wa Wa Wa

Post by JiaYun »

Still WA....:cry:

[cpp]deleted
[/cpp]
Last edited by JiaYun on Sat Jun 19, 2004 8:17 am, edited 1 time in total.
LittleJohn
Learning poster
Posts: 83
Joined: Wed Feb 27, 2002 2:00 am
Location: Taiwan

Post by LittleJohn »

Maybe you should try with a bigger input range than the problem's description, I guess.
JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

Post by JiaYun »

You mean the maximum length of each line? I modified it to 10001, but still WA.... :cry:
Post Reply

Return to “Volume 100 (10000-10099)”