Page 2 of 11

Tell me Why 444 always Tme limit exceeds?

Posted: Mon Sep 16, 2002 9:09 am
by razibcse

Code: Select all

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MAX 100
void encode(char mas[],long b);
void decode(char mas[],long b);
void rev(int n);

void main()
{
char mas[MAX];
long p,b;

while(gets(mas))
{
b=strlen(mas);

if(!isdigit(mas[0]))
  p=0;
else if(isdigit(mas[0]))
  p=1;
if(!p)
 encode(mas,b);
else if(p)
 decode(mas,b);
}

}

void encode(char mas[],long b)
{
long a,n;
for(a=b-1;a>=0;a--)
 {

 n=mas[a];
 rev(n);
 
 }
printf("\n");
}

void decode(char mas[],long b)
{
char ch;
long marker,x,y,z,a,nn,de[MAX];

for(a=0;a<b;a++)
  de[a]=mas[a]-48;

marker=1;
for(;;)
{

x=b-marker;
marker++;
y=b-marker;
nn=10*de[x]+de[y];
if(nn>=32)
    {
    ch=(char)nn;
    printf("%c",ch);
    if(marker<b)
     marker++;
    }

else if(nn<32)
  {
  marker++;
  z=b-marker;
  nn=100*de[x]+10*de[y]+de[z];
  ch=(char)nn;
  printf("%c",ch);
  if(marker<b)
  marker++;
  }
if(marker==b) break;
}
printf("\n");
}
void rev(int n)
{
int a,b,c,d[10],e,f;


 for(c=0;;c++)
  {
  a=n%10;
  d[c]=a;
  b=n/10;
  if(b>=10)
   {
   n=b;
   }
  else
   {
   e=c+1;
   d[e]=b;
   break;
   }

  }
 for(f=0;f<=e;f++)
  printf("%ld",d[f]);

}

444

Posted: Thu Oct 24, 2002 1:04 pm
by Eric
Why I get wrong answer? :-?

Re: 444

Posted: Sun Oct 27, 2002 4:28 pm
by Robbie
Try this :
input :
abc

798999
:wink:

GGG

Posted: Sun Oct 27, 2002 4:43 pm
by Eric
inputs:
  • abc
    798999
    GGG
outputs:
  • 998979
    cba
    171717
Isn't it?

Posted: Sun Oct 27, 2002 6:11 pm
by Robbie
Eric wrote:inputs:
  • abc
    798999
    GGG
outputs:
  • 998979
    cba
    171717
Isn't it?
Hm..., my input isn't like that.
I want to tell you that there may be some spaces like this :

Code: Select all

    
input :
abc

       798999      

cba 
Good luck !

GGG :P

Still WA

Posted: Mon Oct 28, 2002 4:03 pm
by Eric
Thanks for your great help.
However, I go on to get wrong answer.
Still don't know where the problem is. :(

Re: Still WA

Posted: Mon Oct 28, 2002 6:50 pm
by Robbie
How about this :

Code: Select all

input
abc
    abc
      (blank line )
    798999

output
998979
99897923232323

cba 
701997118012300111111117
3333332351100101110150141120123101411792310178
GGG :D

Accepted

Posted: Tue Oct 29, 2002 11:31 am
by Eric
Thanks a lot.
I finally manage to tackle the bugs in my program and get accpeted.
This is a really interesting problem. :D

Posted: Sat Nov 23, 2002 2:04 pm
by knightmare
LOL!

I had a bug with the d character (100 in ascii, the bug was that it eliminated the 00 with atoi) and I only noticed it when I tried to decode the encrypted messages Robbie put in the end of is message (it gave me "Goo luck" instead of "Good luck")

Thnx ;)

No more WA !!

Posted: Mon Dec 16, 2002 7:08 pm
by Moinul(AUST)
Many Thanks to Robbie,

Your last two line

701997118012300111111117
3333332351100101110150141120123101411792310178

helped me identifying a minor mistake in my program :lol:

-Moinul

Posted: Thu Feb 06, 2003 5:00 am
by b3yours3lf
I have take a look at your code and I find two problem
1. the message is at most 80 character long but if it is encode message so the character can be more than 80 character long (max 3* 80=240) so enlarge the array
2.
[c]for(f=0;f<=e;f++)
printf("%ld",d[f]); [/c]
the type if d is array of int but you use long int format to print it

Thanx a lot!!!

Posted: Tue Feb 18, 2003 2:04 am
by razibcse
hi, thanx a lot for ur nice help..

I got it accepted...

I m really grateful to u coz u have given ur so precious time to look my code...

wish u good luck..
Razib

WA?? Why??

Posted: Sun Jun 01, 2003 3:36 pm
by neowarez
I have the same problem I dont no why but my source give me WA...

Why??

[pascal]

Program Acm_444(Input, Output);
Var
Letra: Char;
Dado: Integer;
Result: AnsiString;

Function Reverse(X: Integer): String;
Var
Y, Temp: String;
I, Outro: Integer;
Begin
Str(X, Y);
Temp:='';
For I:=Length(Y) DownTo 1 Do
Temp:=Temp+Copy(Y, I, 1);
Reverse:=Temp
End;

Procedure Reverse2(X: String);
Var
Temp: String;
I, Outro: Integer;
Begin
Temp:='';
For I:=Length(X) DownTo 1 Do
Temp:=Temp+Copy(X, I, 1);
Val(Temp, Dado, Outro);
End;

Procedure Encode;
Var
I, X: Integer;
Begin
Result:='';
If Not (Ord(Letra)=13) Then
Result:=Reverse(Ord(Letra));
If Not EoLn(Input) Then
Repeat
Read(Input, Letra);
If Not (Ord(Letra)=10) Then
Result:=Reverse(Ord(Letra))+Result;
Until EoLn(Input);
WriteLn(Output, Result);
End;

Procedure Decode;
Var
Letras: String;
Letra2: String[2];
Outro: Integer;
Begin
Result:='';
Letras:='';
Letras:=Letras+Letra;
Read(Input, Letra);
Letras:=Letras+Letra;
Reverse2(Letras);
If Not ((Upcase(Chr(Dado)) In ['A'..'Z']) Or (Dado In [32..63])) Then
Begin
Read(Input, Letra);
Letras:=Letras+Letra;
Reverse2(Letras);
End;
Result:=Chr(Dado)+Result;
If Not EoLn(Input) Then
Repeat
Letras:='';
Read(Input, Letra2);
Letras:=Letras+Letra2;
Reverse2(Letras);
If Not ((Upcase(Chr(Dado)) In ['A'..'Z']) Or (Dado In [32..63])) Then
Begin
Read(Input, Letra);
Letras:=Letras+Letra;
Reverse2(Letras);
End;
Result:=Chr(Dado)+Result;
Until EoLn(Input);
WriteLn(Output, Result);
End;

Procedure GetData;
Begin
Repeat
Read(Input, Letra);
If Ord(Letra) In [48..57] Then
Decode
Else
Encode;
ReadLn(Input);
Until EoF(Input);
End;

BEGIN
GetData;
END.
[/pascal]

Thanks.. :-? :-?

444 - Encoder and Decoder

Posted: Mon Jul 28, 2003 9:01 am
by Zhao Le
I don't understand, I have tested a lot.

But still got WA.

Any anyone help me or give some test code.

Thanks in advance.

The code is deleted.

RE:Why #444 WA?

Posted: Mon Jul 28, 2003 4:36 pm
by Culter
Try input:

Code: Select all

32
My ACC program generates:

Code: Select all

A
and yours:

Code: Select all

W
but I haven't found mistake in your code.