444 - Encoder and Decoder
Moderator: Board moderators
-
- New poster
- Posts: 14
- Joined: Sun May 26, 2002 1:54 pm
- Location: China
Serious problem about 444
Help!
Why I got a SIGSEGV runtime error during 444?
I have modified my source for over 10 times!!!![:o](./images/smilies/icon_eek.gif)
Why I got a SIGSEGV runtime error during 444?
I have modified my source for over 10 times!!!
![:o](./images/smilies/icon_eek.gif)
Hi!
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:](./images/smilies/icon_wink.gif)
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
![:)](./images/smilies/icon_smile.gif)
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:](./images/smilies/icon_wink.gif)
-
- New poster
- Posts: 7
- Joined: Wed Jun 05, 2002 3:27 pm
- Location: Portugal
- Contact:
-
- New poster
- Posts: 14
- Joined: Sun May 26, 2002 1:54 pm
- Location: China
I got accepted!
![:D](./images/smilies/icon_biggrin.gif)
When there is a blank input, I just print a blank line.
Then I got ACCEPT!
Thanks to everybody!
![:D](./images/smilies/icon_biggrin.gif)
Problem 444(Encoder and Decoder) again if you please
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]
![:-?](./images/smilies/icon_confused.gif)
[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]
ACM 444
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]
[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]