Page 5 of 11
Posted: Thu Sep 15, 2005 11:12 pm
by Jan
Your code is correct. I just increased your array size and got it Accepted.
Use
You will get Accepted. And delete the code you posted

.
444:why i get COMPILE ERROR?
Posted: Tue Nov 01, 2005 4:59 am
by silvere
run:gcc -g -o coder coder.c
ok.
but i get CE.WHY?
(forgive my poor english and so many functions;-)
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int reverse(char* str)
{
char c;
int i,j;
i=0;
j=strlen(str)-1;
while(i<j)
{
c=str[i];
str[i]=str[j];
str[j]=c;
i++;
j--;
}
return 0;
}
char* encode(char* str,char* res)
{
int i;
for(i=0;i<strlen(str) && str[i]!='\n' && str[i]!='\r';i++)
{
sprintf(res,"%s%d",res,str[i]);
}
reverse(res);
return res;
}
//察看字符是否在规定的范围内
int judge_char(char c)
{
if ( (c>='A' && c<='Z') || (c>='a' && c<='z') || c==' ' || c=='!' || c==',' || c=='.' || c==';' || c==':' || c=='?')
return 0;
else
return 1;
}
char* decode(char * str,char* res)
{
char j[1024]="",k[1024]="";
int length,i,res_len=0;
reverse(str);
strcpy(k,str);
length=strlen(str);
bzero(res,1024);
for(i=0;i<length ;i++)
{
if(!(k[i]<='9' && k[i]>='0'))
{
str++;
continue;
}
strncpy(j,str,2);
j[2]='\0';
if(judge_char(atoi(j)))
{
strncpy(j,str,3);
j[3]='\0';
if(judge_char(atoi(j)))
{
exit(1);
}
i+=2;
str+=3;
res_len++;
sprintf(res,"%s%c",res,atoi(j));
}
else
{
i++;
str+=2;
res_len++;
sprintf(res,"%s%c",res,atoi(j));
}
}
res[res_len]='\0';
return res;
}
int include_dig(char *str)
{
int i;
for(i=0;i<strlen(str);i++)
{
if(str[i]<='9' && str[i]>='0')
return 1;
}
return 0;
}
int include_char(char *str)
{
int i;
for(i=0;i<strlen(str);i++)
if(!judge_char(str[i]) && str[i]!=' ')
return 1;
return 0;
}
int main()
{
char res[1024];
char* str=(char*)malloc(sizeof(char)*1024);
bzero(res,1024);
bzero(str,1024);
size_t len;
while(getline(&str,&len,stdin) >0)
{
if(include_char(str))
printf("%s\n",encode(str,res));
else if(include_dig(str))
printf("%s\n",decode(str,res));
else
{
printf("%s\n",res);
}
bzero(res,1024);
bzero(str,1024);
}
free(str);
return 0;
}
Posted: Tue Nov 01, 2005 6:47 pm
by Solaris
In response to your submission you should get a mail in your specified address (if you had not turned that option off). In that mail the details about the compile error i.e. the error messages are provided. Those emails help me a lot to get rid of my CEs
Anyway I have tried to run your code in VC. But it shows the following error messages:
1. error C2065: 'bzero' : undeclared identifier
2. error C2065: 'getline' : undeclared identifier
I think u know what to do

444 WA
Posted: Tue Jan 24, 2006 2:00 pm
by akayg
444
i think my code is correct.
i tested it many cases that i saw in this forum.
but, i got WA.
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char buf[880];
char tmp[2];
char tmp2[3];
int num;
int i;
while (fgets(buf, sizeof(buf), stdin))
{
buf[strlen(buf)-1] = '\0';
/*
while (buf[strlen(buf)-1] == ' ')
buf[strlen(buf)-1] = '\0';
*/
for (i=strlen(buf)-1; i>=0; i--) {
if (buf[i] >= 48 && buf[i] <= 57) {
if (buf[i] == '1') {
tmp2[0] = buf[i--];
tmp2[1] = buf[i--];
tmp2[2] = buf[i];
num = atoi(tmp2);
} else {
tmp[0] = buf[i--];
tmp[1] = buf[i];
num = atoi(tmp);
}
printf("%c", num);
} else if ((buf[i] >= 65 && buf[i] <=90) ||
(buf[i]>=97 && buf[i]<=122) || buf[i] ==32 || buf[i]==33 ||
buf[i]==44 || buf[i]==46 || buf[i]==58 || buf[i]==59 || buf[i]==63)
{
if (buf[i] > 99)
printf("%d%d%d", buf[i]%10, buf[i]/10%10, buf[i]/10/10);
else
printf("%d%d", buf[i]%10, buf[i]/10);
}
}
printf("\n");
}
return 0;
}
who has the idea?
thanks for read.
Posted: Tue Jan 24, 2006 4:59 pm
by chunyi81
You were very careless.
Read the problem description again:
The following is an ASCII table of the valid characters in a message:
"A" 65 "a" 97 " " 32
"B" 66 "b" 98 "!" 33
. . "," 44
. . "." 46
. . ":" 58
"Y" 89 "y" 121 ";" 59
"Z" 90 "z" 122 "?" 63
You left out the ";" character. (ASCII 59)
that's my mistake.
Posted: Wed Jan 25, 2006 2:09 am
by akayg
i edit my code.
but, No aceepted.
444 Why WA? I Have to finish!!!!! HELP!!!
Posted: Fri Jan 27, 2006 3:00 pm
by Psyco
#include<stdio.h>
#include<string.h>
char str[10000]; int i, j, len;
int main()
{
while(gets(str))
{
len=strlen(str);
for(i=len;i>=0;i--)
{
switch(str)
{
case ' ' : printf("23"); str=0; break; case '!' : printf("33"); str=0; break; case ',' : printf("44"); str=0; break; case '.' : printf("64"); str=0; break; case ':' : printf("85"); str=0; break; case ';' : printf("95"); str=0; break; case '?' : printf("36"); str=0; break; case 'a' : printf("79"); str=0; break; case 'b' : printf("89");str=0; break; case 'c' : printf("99");str[i]=0; break; case 'd' : printf("001");str[i]=0; break; case 'e' : printf("101");str[i]=0; break; case 'f' : printf("201");str[i]=0; break; case 'g' : printf("301");str[i]=0; break; case 'h' : printf("401");str[i]=0; break; case 'i' : printf("501");str[i]=0; break; case 'j' : printf("601");str[i]=0; break; case 'k' : printf("701");str[i]=0; break; case 'l' : printf("801");str[i]=0; break; case 'm' : printf("901");str[i]=0; break; case 'n' : printf("011");str[i]=0; break; case 'o' : printf("111");str[i]=0; break; case 'p' : printf("211");str[i]=0; break; case 'q' : printf("311");str[i]=0; break; case 'r' : printf("411");str[i]=0; break; case 's' : printf("511");str[i]=0; break; case 't' : printf("611");str[i]=0; break; case 'u' : printf("711");str[i]=0; break; case 'v' : printf("811");str[i]=0; break; case 'w' : printf("911");str[i]=0; break; case 'x' : printf("021");str[i]=0; break;
case 'y' : printf("121");str[i]=0; break; case 'z' : printf("221");str[i]=0; break; case 'A' : printf("56"); str[i]=0; break; case 'B' : printf("66"); str[i]=0; break; case 'C' : printf("76"); str[i]=0; break; case 'I' : printf("37"); str[i]=0; break;case 'O' : printf("97"); str[i]=0; break;case 'U' : printf("58"); str[i]=0; break; case 'D' : printf("86"); str[i]=0; break; case 'J' : printf("47"); str[i]=0; break;case 'P' : printf("08"); str[i]=0; break;case 'V' : printf("68"); str[i]=0; break; case 'E' : printf("96"); str[i]=0; break; case 'K' : printf("57"); str[i]=0; break;case 'Q' : printf("18"); str[i]=0; break;case 'W' : printf("78"); str[i]=0; break; case 'F' : printf("07"); str[i]=0; break; case 'L' : printf("67"); str[i]=0; break;case 'R' : printf("28"); str[i]=0; break;case 'X' : printf("88"); str[i]=0; break; case 'G' : printf("17"); str[i]=0; break; case 'M' : printf("77"); str[i]=0; break;case 'S' : printf("38"); str[i]=0; break;case 'Y' : printf("98"); str[i]=0; break; case 'H' : printf("27"); str[i]=0; break; case 'N' : printf("87"); str[i]=0; break;case 'T' : printf("48"); str[i]=0; break;case 'Z' : printf("09"); str[i]=0; break;
default :
if(str[i]!=0)
{
if( i>=2 && (str[i]-'0')*100+(str[i-1]-'0')*10+(str[i-2]-'0')>=32 && (str[i]-'0')*100+(str[i-1]-'0')*10+(str[i-2]-'0')<=122 && str[i-1]!=' ' && str[i-2]!=' '){
printf("%c",(str[i]-'0')*100+(str[i-1]-'0')*10+(str[i-2]-'0'));
str[i-2]=str[i-1]=str[i]=0;
i-=2;
}
else if( (str[i-1]-'0')+(str[i]-'0')*10>=32 && i>=1 && str[i]<='9' && str[i]>='0' && str[i-1]<='9' && str[i]>='0' && str[i]!=' ' && str[i-1]!=' ')
{
printf("%c",(str[i-1]-'0')+(str[i]-'0')*10);
str[i]=str[i-1]=0; i--;
}
else printf("%c",str[i]);
}
break;
}
}
printf("\n");
}
return 0;
}
Why WA?
I Want to Error Data.... Plz !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
444 RE!!! sumbuddy help meee....
Posted: Sun Jun 18, 2006 8:53 am
by kolpobilashi
may b my logic is wrong.but the code below gave the correct output for the sample input given in the problem. at 1st i use the "strrev" function in the "decoder" part and got CE and got the following msg
[size=18]04657187_24.c: In function `void decoder(char *)':
04657187_24.c:43: implicit declaration of function `int strrev(...)'[/size]
later i did that manually and got RE and got
[size=12][/size]
"[size=18]Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Before crash, it ran during 0.002 seconds[/size]"
Posted: Sun Jun 18, 2006 10:53 pm
by emotional blind
May be gcc does not support strrev() function:
Posted: Sun Jun 18, 2006 11:23 pm
by emotional blind
problem description
Code: Select all
spy's message is at most 80 characters long,
but encoded messege may be 3*80=240 character long at maximum, isnt it?
So take array size 241 to avoid run time error.
Posted: Mon Jun 19, 2006 4:50 am
by kolpobilashi
thanx a lot. i have done wat u told,increased the array size upto "244"
but this time got WA
wat's wrong in my code?

Posted: Mon Jun 19, 2006 4:19 pm
by emotional blind
check your revDigit() function
what should be the reverse of 100,
1 or 001
think about it
Posted: Mon Jun 19, 2006 4:59 pm
by emotional blind
before
add this
Code: Select all
if(len==3){
if(rev<10)printf("00");
else if(rev<100)printf("0");
}
else if(len==2){
if(rev<10)printf("0");
}
another thing
it is a good practice to give your code in code(as I did),
otherwise it is very difficult to read it
and dont forget to remove your code after get ACCEPTED
Posted: Mon Jun 19, 2006 5:41 pm
by kolpobilashi
thanx a lot Arif bhai. atlast i got AC. thnx 4 all the suggestions.

444 WA, plz help me!!
Posted: Sun Aug 06, 2006 12:46 pm
by bongssi
I don't know why it's wrong. I have tried many test cases, but it seeems to work correctly. Please find bugs in this program!!
#include <stdio.h>
#include <string.h>
char result[1000], input[1000];
int result_top, str_length;
int power(int m, int n){ /* returns m^n */
int i, result=1;
for(i=0; i<n; i++)
result *= m;
return result;
}
void init_result(char result[1000]){
int i;
for(i=0; i<1000; i++)
result = 0;
}
void decode(char input[1000], char result[1000]){
int i;
char code;
for(i=str_length-1; i>=0; ){
code = 0;
while(!(code>=32 && code<=122)){
code *= 10;
code += input[i--] - '0';
}
result[result_top++] = code;
}
}
void incode(char input[1000], char result[1000]){
int i, digits;
char code, tmp;
for(i=0; i<str_length; i++){
code = input;
digits = 0;
tmp = code;
do{ /*get number of digits*/
tmp/=10;
digits++;
}while(tmp > 0);
tmp = code;
while(digits >= 1){
result[result_top++] = (tmp / power(10, digits-1) + '0');
tmp %= power(10, digits-1);
digits--;
}
}
}
int main(void){
int is_decode, i;
while(scanf("%[^\n]", input) == 1){
init_result(result);
str_length = strlen(input);
if(str_length > 80) str_length = 80;
result_top = 0;
if(input[0] >= '0' && input[0] <= '9') is_decode = 1;
else is_decode = 0; /*incode*/
if(is_decode){ /*decoding*/
decode(input, result);
for(i=0; i<result_top; i++)
printf("%c", result);
printf("\n");
}
/*incoding*/
else{
incode(input, result);
for(i=result_top-1; i>=0; i--)
printf("%c", result);
printf("\n");
}
fflush(stdin);
}
return 0;
}