444 - Encoder and Decoder

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

Moderator: Board moderators

Post Reply
FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath »

can someone tell me what's the common problems with this question??
thanks
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

If there is one,
I think that is the encrypted message may be > 80 characters...
FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath »

I find my mistake
thanks
Sherman MXF
New poster
Posts: 14
Joined: Sun May 26, 2002 1:54 pm
Location: China

Serious problem about 444

Post by Sherman MXF »

Help!
Why I got a SIGSEGV runtime error during 444?
I have modified my source for over 10 times!!! :o
cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Hi!

Post by cyfra »

Hi!

I had the similar problem...

the only thing you have to do is to make one if...
There is a test case with empty line...

And my program tried to read from ..
I don't know from :)

And it gave R.E.

So make one if in your program and you will propably have A.C.

I hope it will help

Good Luck :wink:
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen »

i had similar problem (R.E.) but when I increased the array size from 80 to 400 it got AC. gook luck :P
Ivan Silva
New poster
Posts: 7
Joined: Wed Jun 05, 2002 3:27 pm
Location: Portugal
Contact:

Post by Ivan Silva »

So if there is a blank line in the input what should we print?
a \n
or just ingore that input?

Cause my arrays size are 400 and my program is ignoring the blank lines...
but i still got WA, and of course the output is correct for the given input :)

-Ivan
Sherman MXF
New poster
Posts: 14
Joined: Sun May 26, 2002 1:54 pm
Location: China

I got accepted!

Post by Sherman MXF »

:D
When there is a blank input, I just print a blank line.
Then I got ACCEPT!
Thanks to everybody!
:D
mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt

Problem 444(Encoder and Decoder) again if you please

Post by mido »

What's wrong with this...I get a wrong answer :-? :
[cpp]
#include <iostream.h>
#include <string.h>

char *str,*res,*res2,temp;
int i,j,num,ones,tens,hundreds;

void main()
{
str=new char[85];
res=new char[85];
res2=new char[270];
while (cin.getline(str,85,'\n'))
{
if (str[0]>='0' && str[0]<='9')
{
j=0;
for (i=0;i<strlen(str)/2;i++)
{
temp=str;
str=str[strlen(str)-1-i];
str[strlen(str)-1-i]=temp;
}
i=0;
while (i<strlen(str))
{
num=0;
if (str=='1')
{
num+=100;
i++;
}
num+=(int(str)-int('0'))*10;
num+=int(str[i+1])-int('0');
i++;
i++;
res[j]=char(num);
j++;
}
res[j]=0;
for (j=0;j<strlen(res);j++)
cout<<res[j];
cout<<endl;
}
else
{
i=0;
j=0;
while (i<strlen(str))
{
num=0;
num=int(str);
if (num<=100)
{
ones=num%10;
tens=(num/10)%10;
res2[j+1]=char(ones+int('0'));
res2[j]=char(tens+int('0'));
j++;
j++;
}
else
{
ones=num%10;
tens=(num/10)%10;
hundreds=(num/100);
res2[j+2]=char(ones+int('0'));
res2[j+1]=char(tens+int('0'));
res2[j]=char(hundreds+int('0'));
j++;
j++;
j++;
}
i++;
}
res2[j]=0;
for (j=j-1;j>=0;j--)
cout<<res2[j];
cout<<endl;
}
}
}
[/cpp]
10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

I read your code and found nth wrong (without testing of course =P). But I found one minor problem, I donno if it matters.

The input line read in should not be <= 80, since if the text is an encoded text, the length of the text may be > 80.
mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt

Post by mido »

Hmmm...well I tried to enlarge the arrays to tens of thousands...still WA...try again, I guess..thanks in advance
mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt

Post by mido »

Yikes..found a nasty bug..there's a line saying
if (num<=100)
Should have been [if num < 100]..in other words the letter 'd'(ascii 100) would mess up the thing..harsh world, I guess.

Oh look I got accepted. Thanks 10153EN.
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

ACM 444

Post by htl »

I think the code doens't have any bug. What's wrong with the code?
[c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main(void)
{
int code[80],x,y,temp;
char buffer[1000],c;
while(1)
{
for(x=0;(c=getchar())!='\n';x++)
if(c==EOF)
exit(0);
else
buffer[x]=c;
buffer[x]='\0';
if(buffer[0]>='0' && buffer[0]<='9')
{
for(x=0,y=strlen(buffer)-1;x<y;x++,y--)
{
c=buffer[x];
buffer[x]=buffer[y];
buffer[y]=c;
}
for(x=0,temp=0;buffer[x]!='\0';x++)
{
temp=temp*10+buffer[x]-'0';
if(temp>30)
{
printf("%c",temp);
temp=0;
}
}
printf("\n");
}
else
{
for(x=0,y=strlen(buffer)-1;y>=0;x++,y--)
code[x]=buffer[y];
for(x=0;x<strlen(buffer);x++)
if(code[x]>=100)
printf("%d%d%d",code[x]%10,code[x]%100/10,code[x]/100);
else
printf("%d%d",code[x]%10,code[x]/10);
printf("\n");
}
}
}
[/c]
Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard »

i think, nothing. it got accepted for me.
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post by htl »

I've sent it and got accepted. I just don't know why I couldn't get accepted before? The only difference is the length of buffer is 1000 not 100.
Post Reply

Return to “Volume 4 (400-499)”