Page 10 of 11
Re: 444 - Encoder and Decoder (runtime Error!)
Posted: Sun Jul 06, 2014 1:44 am
by sidsi
brianfry713 wrote:I believe there is a blank line in the judge's input.
i got accepted after considering the massage can be more than 100 characters long. first it was TE while i assumed 90 would be good. then directly i consider 1000 and got accptd.

Re: 444 - Encoder and Decoder (runtime Error!)
Posted: Thu Jul 31, 2014 3:31 am
by mgavin2
debug my WA code and tell me where I fail

(because the code passes a lot of tests)
Re: 444 - Encoder and Decoder (runtime Error!)
Posted: Thu Jul 31, 2014 3:33 pm
by lighted
Use search box and enter problem number 444 and you will get so many threads with many tests there.
I think they are enough to solve this problem.
For example some input from that threads.
RAT wrote:try this input:
Code: Select all
00120110179
1019523856436221
fd
998979
cbaL
332312179862310199501872379231018117927
362395238523642344233323
369585644433
001998979
abcd
output will be:
Code: Select all
aefd
z?.: ;e
001201
abc
67798999
Have a Nice Day !
! , . : ; ?
!,.:;?
abcd
001998979
UFP2161 wrote:You can create your own inputs/outputs.. assuming your encoding is correct since that part is rather trivial. Just use that output as your input for decoding.. =)
But, if you must insist, here's some random test data:
Input:
? ,,V!H.:!;
,HdCqgiA
e!ER!o hI,X?.?; S?SyHv. ,N,Q
::zr
?M?aEHQdbgC,R;umOI?jv?!M F
r!:Y?.!Fx?;rm;PS
JX, ::;SdY.,FM; G:.,?C
s ..EG!XLDm,H!bk
?wwQ!:Im w,F.F WOsbGja;NN
LA;hr!mdsUQ,!zd; :zrD?
Output:
9533856427336844442336
56501301311760012744
184487442364811271213836382395366436884437401232311133289633101
4112218585
0723773336811601363797901711952844763018900118279679367736
38089590141195360210733643698853341123
763644648517239577074464980013895858523448847
7018933274490186678833179664642323511
2387879579601178951197782307640744911239013785331891191136
36864112218523950012213344185851100190133411401955667
And vice versa.
osan wrote:INPUT
abc
798999
Have a Nice Day !
9900199
abbadc
aaa
11167001
ABC
AbCD
OUTPUT
998979
cba
332312179862310199501872379231018117927
cdc
9900179898979
797979
dLo
766656
86768956
Robbie wrote:How about this :
Code: Select all
input
abc
abc
(blank line )
798999
output
998979
99897923232323
cba
701997118012300111111117
3333332351100101110150141120123101411792310178
GGG

Hope it will help
Re: 444 - Encoder and Decoder (runtime Error!)
Posted: Fri Aug 01, 2014 12:15 am
by mgavin2
Thank you. someone posting :
701997118012300111111117
3333332351100101110150141120123101411792310178
helped me change
to
but it wasnt until I added
Code: Select all
if (cin.peek() == cin.eof()) return false;
in my getInput() function that I finally got AC
444 why getting wrong answer?
Posted: Wed Aug 20, 2014 12:02 pm
by sajal2k8
Here is my code:
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
string s;
char p[10000];
int i=0,a,b,c,d,re=0;
while(getline(cin,s))
{
for (std::string::reverse_iterator rit=s.rbegin(); rit!=s.rend(); ++rit)
{
p
=*rit;
i++;
}
for(int j=0;j<s.length();j++)
{
if((p[j]>64 && p[j]<91) || (p[j]>96 && p[j]<123))
{
a=p[j];
for( ; a!= 0 ; )
{
re = re * 10;
re = re + a%10;
a = a/10;
}
cout<<re;
re=0;
}
else
{
b=p[j]-'0';
b=b*10;
c=p[j+1]-'0';
b=b+c;
j++;
if((b>64 && b<91) || (b>96 && b<100))
{
cout<<(char)b;
}
else if(b==32 || b==33 || b==44|| b==46|| b==58 || b==59 || b==63)
{
if(b==32)
cout<<(char)b;
else if(b==33)
cout<<(char)b;
else if(b==44)
cout<<(char)b;
else if(b==46)
cout<<(char)b;
else if(b==58)
cout<<(char)b;
else if(b==59)
cout<<(char)b;
else if(b==63)
cout<<(char)b;
}
else
{
b=b*10;
d=p[j+1]-'0';
j++;
b=b+d;
cout<<(char)b;
}
}
}
cout<<endl;
i=0;
}
return 0;
}
Getting wrong answer but cannot find a problem. Please help. Thanks in advance 
Re: 444 why getting wrong answer?
Posted: Wed Aug 20, 2014 4:13 pm
by lighted
See thread
http://acm.uva.es/board/viewtopic.php?f ... 41#p370473
Use code tags. It is difficult to understand your code.
Re: 444 - Encoder and Decoder
Posted: Wed Aug 20, 2014 8:03 pm
by brianfry713
sajal2k8 next time post in the existing thread.
Try running your code on the sample input.
Re: 444 - Encoder and Decoder
Posted: Thu Aug 21, 2014 7:40 am
by sajal2k8
Hey brainfry713,
Can you please run and tell me the problem. I really can't find:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
using namespace std;
int main()
{
string s,n="001",m="0";
char p[10000];
int i=0,a,b,c,d,re=0,g=0;
while(getline(cin,s))
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
if(s=="")
{
if (cin.peek() == cin.eof()) return false;
// cout<<endl;
}
else
{
for (std::string::reverse_iterator rit=s.rbegin(); rit!=s.rend(); ++rit)
{
p
=*rit;
i++;
}
for(int j=0;j<s.length();j++)
{
if((p[j]>64 && p[j]<91) || (p[j]>96 && p[j]<123) || p[j]==32 || p[j]==33 || p[j]==44|| p[j]==46|| p[j]==58 || p[j]==59 || p[j]==63)
{
a=p[j];
for( ; a!= 0 ; )
{
re = re * 10;
re = re + a%10;
a = a/10;
}
if(re<10)
{
if(re==1)
cout<<n;
else
cout<<m<<re;
re=0;
}
else
cout<<re;
re=0;
}
else
{
b=p[j]-'0';
b=b*10;
c=p[j+1]-'0';
b=b+c;
j++;
if((b>64 && b<91) || (b>96 && b<100))
{
cout<<(char)b;
}
else if(b==32 || b==33 || b==44|| b==46|| b==58 || b==59 || b==63)
{
if(b==32)
{
cout<<(char)b;
}
else if(b==33)
cout<<(char)b;
else if(b==44)
cout<<(char)b;
else if(b==46)
cout<<(char)b;
else if(b==58)
cout<<(char)b;
else if(b==59)
cout<<(char)b;
else if(b==63)
cout<<(char)b;
}
else
{
b=b*10;
d=p[j+1]-'0';
j++;
b=b+d;
cout<<(char)b;
}
}
}
cout<<endl;
i=0;
}
}
return 0;
}
Thanks 
Re: 444 - Encoder and Decoder
Posted: Thu Aug 21, 2014 8:14 pm
by brianfry713
Input:
Output should be 7923
Re: 444 - Encoder and Decoder
Posted: Mon Sep 22, 2014 5:50 pm
by nasim.ruet
Please someone help...
i cannot find for what input it is wrong ans. can u tell me.. the input and my wrong output...
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
char message[1000];
int output[1000];
while(cin.getline(message,1000))
{
int i,l,c=0,temp,total,a,number=1;
l = strlen(message);
for(i=l-1; i>=0; i--)
{
if(message
>=48 && message<=57)
{
output[c++] = message-48;
if(message[i-1]==' ')
break;
}
else
{
total = 0;
temp = message-0;
while(temp)
{
a = temp%10;
temp /= 10;
total = total*10 + a;
}
output[c++] = total;
number =0;
}
}
if(number == 0)
{
for(i=0; i<c; i++)
{
if(output==1)
printf("001");
else
printf("%d",output);
}
printf("\n");
}
else
{
for(i=0; i<c; i++)
{
total = 0;
while(total < 32)
{
total = total*10 + output[i++];
}
i--;
printf("%c",total);
}
printf("\n");
}
}
return 0;
}
Re: 444 - Encoder and Decoder
Posted: Mon Sep 22, 2014 6:19 pm
by lighted
Try to check input in this thread first. There are lots of input to test your code.
Sedefcho wrote:Here is some test data for you:
INPUT
Code: Select all
abcdef!,.:;?
abcdef!,.:;?ABCDZYV
369585644433201101001998979
68980986766656369585644433201101001998979
a bcdef!,.:;?ABCDZY V
68232323980986766656369585644433201101001998923232379
zyxwvnPQST abracadarbra
79411894117900179997941189792348381808011811911021121221
abczzzzzzYYYYYYY def!,.:;?ABCDZYV
689809867666563695856444332011010012323232398989898989898221221221221221221998979
OUTPUT
Code: Select all
369585644433201101001998979
68980986766656369585644433201101001998979
abcdef!,.:;?
abcdef!,.:;?ABCDZYV
68232323980986766656369585644433201101001998923232379
a bcdef!,.:;?ABCDZY V
79411894117900179997941189792348381808011811911021121221
zyxwvnPQST abracadarbra
689809867666563695856444332011010012323232398989898989898221221221221221221998979
abczzzzzzYYYYYYY def!,.:;?ABCDZYV
Check if you get the same answers.
Btw, it is a bad habit to post directly your code and
just say "I got WA"

Try to post code after all other methods
for finding help have failed or if someone asks you to post your code.
That's just my personal opinion.
UFP2161 wrote:You can create your own inputs/outputs.. assuming your encoding is correct since that part is rather trivial. Just use that output as your input for decoding.. =)
But, if you must insist, here's some random test data:
Input:
? ,,V!H.:!;
,HdCqgiA
e!ER!o hI,X?.?; S?SyHv. ,N,Q
::zr
?M?aEHQdbgC,R;umOI?jv?!M F
r!:Y?.!Fx?;rm;PS
JX, ::;SdY.,FM; G:.,?C
s ..EG!XLDm,H!bk
?wwQ!:Im w,F.F WOsbGja;NN
LA;hr!mdsUQ,!zd; :zrD?
Output:
9533856427336844442336
56501301311760012744
184487442364811271213836382395366436884437401232311133289633101
4112218585
0723773336811601363797901711952844763018900118279679367736
38089590141195360210733643698853341123
763644648517239577074464980013895858523448847
7018933274490186678833179664642323511
2387879579601178951197782307640744911239013785331891191136
36864112218523950012213344185851100190133411401955667
And vice versa.
Re: 444 - Encoder and Decoder
Posted: Tue Sep 23, 2014 8:49 am
by sajal2k8
Still getting WA. Give me some input for which this code will fail. I have tried existing ones:
Code: Select all
#include <iostream>
#include <string>
#include <stdlib.h>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
using namespace std;
int main()
{
string s,n="001",m="0";
char p[10000];
int i=0,a,b,c,d,re=0,g=0;
while(getline(cin,s))
{
if(s=="")
{
cout<<endl;
}
else
{
for (std::string::reverse_iterator rit=s.rbegin(); rit!=s.rend(); ++rit)
{
p[i]=*rit;
i++;
}
for(int j=0;j<s.length();j++)
{
if((p[j]>64 && p[j]<91) || (p[j]>96 && p[j]<123) || p[j]==32 || p[j]==33 || p[j]==44|| p[j]==46|| p[j]==58 || p[j]==59 || p[j]==63 )
{
a=p[j];
for( ; a!= 0 ; )
{
re = re * 10;
re = re + a%10;
a = a/10;
}
if(re<10)
{
if(re==1)
cout<<n;
else
cout<<m<<re;
re=0;
}
else
cout<<re;
re=0;
}
else
{
b=p[j]-'0';
b=b*10;
c=p[j+1]-'0';
b=b+c;
j++;
if((b>64 && b<91) || (b>96 && b<100))
{
cout<<(char)b;
}
else if(b==32 || b==33 || b==44|| b==46|| b==58 || b==59 || b==63)
{
if(b==32)
{
cout<<(char)b;
}
else if(b==33)
cout<<(char)b;
else if(b==44)
cout<<(char)b;
else if(b==46)
cout<<(char)b;
else if(b==58)
cout<<(char)b;
else if(b==59)
cout<<(char)b;
else if(b==63)
cout<<(char)b;
}
else
{
b=b*10;
d=p[j+1]-'0';
j++;
b=b+d;
cout<<(char)b;
}
}
}
cout<<endl;
i=0;
}
}
return 0;
}
Thanks in advance

Re: 444 - Encoder and Decoder
Posted: Tue Sep 23, 2014 11:18 am
by lighted
Your code fails input i posted. Do you have file compare or text compare tool? You can use
http://www.diffnow.com
I collected some input from existing ones. I think your output is missing some zeroes.
Input
Code: Select all
zyxwvnPQST abracadarbra
r!:Y?.!Fx?;rm;PS
One is to write an encoderdecoder program here.
To B or not TO be is the QUESTION.
the quick brown fox jumped over the lazy dog :p
Try all the silly cases you can think of
Acc Output(uDebug)
Code: Select all
79411894117900179997941189792348381808011811911021121221
380895901411953602107336436988533411
64101411101401239017941130111141121123411101001111991010014111010011119901110123011792310161150141191123111611235115012310101197
64879737483896581823101401611235115012310189239748236111110112341111123662311148
21185233011110012312122179801231014016112341110181111123001101211901711601230211112012301191111141189237019950171131123101401611
2011112370101150140161123011799923711111121235111015117999231218018015015112310140161123801801792312141148
Your Output
Code: Select all
794118941179001799979411897923483818081181191121121221
38089590141195362107336436988533411
64101411101401239017941130111141121123411101001111991010014111010011119911101231179231016115014119112311161123511501231011197
6487973748389658182310140161123511501231018923974823611111112341111123662311148
211852330111100123121221798012310140161123411101811111230011012119017116012321111201231191111141189237019950171131123101401611
20111123701115014016112311799923711111121235111015117999231218018015015112310140161123801801792312141148
See here
http://ideone.com/3xKRsX
Re: 444 - Encoder and Decoder
Posted: Tue Sep 23, 2014 12:44 pm
by nasim.ruet
Re: 444 - Encoder and Decoder
Posted: Thu Oct 02, 2014 12:21 pm
by moudud99
Can anybody please help me to find my mistake?
I got a lot WA for it.
thanks in advance.