10062 - Tell me the frequencies!
Moderator: Board moderators
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
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
Please help me !!!
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
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
10062
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...
[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]
could anyone examine the code below and tell me why??...
thanx a lot in advance...
[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]
-
- New poster
- Posts: 9
- Joined: Tue Apr 01, 2003 10:03 pm
- Location: Dhaka, Bangladesh
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]
[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]
-
- New poster
- Posts: 9
- Joined: Tue Apr 01, 2003 10:03 pm
- Location: Dhaka, Bangladesh
-
- Learning poster
- Posts: 83
- Joined: Wed Feb 27, 2002 2:00 am
- Location: Taiwan