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

sidsi
New poster
Posts: 7
Joined: Sun Mar 23, 2014 5:28 pm

Re: 444 - Encoder and Decoder (runtime Error!)

Post by sidsi » Sun Jul 06, 2014 1:44 am

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. :(

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

Re: 444 - Encoder and Decoder (runtime Error!)

Post by mgavin2 » Thu Jul 31, 2014 3:31 am

Code: Select all

AC

debug my WA code and tell me where I fail :( (because the code passes a lot of tests)
Last edited by mgavin2 on Fri Aug 01, 2014 12:16 am, edited 1 time in total.
all that matters is AC

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 444 - Encoder and Decoder (runtime Error!)

Post by lighted » Thu Jul 31, 2014 3:33 pm

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 :D
Hope it will help
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

Re: 444 - Encoder and Decoder (runtime Error!)

Post by mgavin2 » Fri Aug 01, 2014 12:15 am

Thank you. someone posting :
701997118012300111111117
3333332351100101110150141120123101411792310178

helped me change

Code: Select all

if (i+2 <= line.length())
to

Code: Select all

if (i+2 < line.length())
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
all that matters is AC

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

444 why getting wrong answer?

Post by sajal2k8 » Wed Aug 20, 2014 12:02 pm

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 :)

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 444 why getting wrong answer?

Post by lighted » Wed Aug 20, 2014 4:13 pm

See thread
http://acm.uva.es/board/viewtopic.php?f ... 41#p370473

Use code tags. It is difficult to understand your code.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 444 - Encoder and Decoder

Post by brianfry713 » Wed Aug 20, 2014 8:03 pm

sajal2k8 next time post in the existing thread.
Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

Re: 444 - Encoder and Decoder

Post by sajal2k8 » Thu Aug 21, 2014 7:40 am

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 :)

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 444 - Encoder and Decoder

Post by brianfry713 » Thu Aug 21, 2014 8:14 pm

Input:

Code: Select all

 a
Output should be 7923
Check input and AC output for thousands of problems on uDebug!

nasim.ruet
New poster
Posts: 10
Joined: Sat Sep 06, 2014 12:44 pm

Re: 444 - Encoder and Decoder

Post by nasim.ruet » Mon Sep 22, 2014 5:50 pm

Please someone help... :oops: :oops:
i cannot find for what input it is wrong ans. can u tell me.. the input and my wrong output... :evil: :evil:
#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;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 444 - Encoder and Decoder

Post by lighted » Mon Sep 22, 2014 6:19 pm

Code: Select all

Use code tags. Like this
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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

Re: 444 - Encoder and Decoder

Post by sajal2k8 » Tue Sep 23, 2014 8:49 am

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 :)

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 444 - Encoder and Decoder

Post by lighted » Tue Sep 23, 2014 11:18 am

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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

nasim.ruet
New poster
Posts: 10
Joined: Sat Sep 06, 2014 12:44 pm

Re: 444 - Encoder and Decoder

Post by nasim.ruet » Tue Sep 23, 2014 12:44 pm

:lol: :lol:

Code: Select all

i got AC. thanks a lot. 
:lol:

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 444 - Encoder and Decoder

Post by moudud99 » Thu Oct 02, 2014 12:21 pm

Can anybody please help me to find my mistake?
I got a lot WA for it.
thanks in advance.

Code: Select all

NO CODE IS HERE!!!!!
Last edited by moudud99 on Thu Oct 02, 2014 4:21 pm, edited 1 time in total.

Post Reply

Return to “Volume 4 (400-499)”