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

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: Why #444 WA?

Post by Obaida » Tue Jul 29, 2008 10:05 am

Seemed very easy problem to me but gave me RTE && i can't find any reason :o .
Someone please help me.

Code: Select all

removed
Last edited by Obaida on Tue Dec 23, 2008 11:49 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

nayimsust
New poster
Posts: 9
Joined: Wed Aug 27, 2008 6:50 pm

444 is easy prob but when i submit my code its show RTE

Post by nayimsust » Fri Aug 29, 2008 9:04 am

my code



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
long long i,j,k,p,q,h;
char a[1000000],b[10],c;
while(gets(a))
{
if(!isdigit(a[0]))
{
for(i=strlen(a)-1;i>=0;--i)
{
j=a;
sprintf(b,"%lld",j);
for(k=strlen(b)-1;k>=0;--k)
printf("%c",b[k]);
}
printf("\n");
}


else
{
for(i=strlen(a)-1;i>=0;--i)
{
q=0;
if(a=='1')
{
h=i;
for(i=h;i>=h-2;--i)
{
b[q]=a;
++q;
}
b[q]=NULL;
++i;
}
else
{
h=i;
for(i=h;i>=h-1;--i)
{
b[q]=a;
++q;
}
b[q]=NULL;
++i;
}
j=atoll(b);
c=j;
printf("%c",c);
}
printf("\n");
}

}
return 0;
}

rajib_sust
New poster
Posts: 16
Joined: Sun Mar 02, 2008 10:34 am
Location: SUST , Sylhet, Bangladesh

Re: Why #444 WA?

Post by rajib_sust » Sat Aug 30, 2008 6:47 pm

Code: Select all

	sprintf(b,"%lld",j);
u r keeping long long number just a 10 size array but long long contain 18 digit most
cheek it
life is beautiful like coding

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Runtime Error

Post by lnr » Thu Oct 02, 2008 5:35 pm

To nayimsust...
Your input array is too large for this problem.
Problem says the input message will be in 80 characters.
You took char a[1000000].

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re:444 geting WA pls help whr is da problem???

Post by abid_iut » Sat Nov 08, 2008 11:57 am

Code: Select all

Removed after AC
Last edited by abid_iut on Sat Jan 03, 2009 7:14 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

porker2008
New poster
Posts: 21
Joined: Wed Oct 08, 2008 7:04 am

To abid_iut

Post by porker2008 » Sat Nov 08, 2008 10:43 pm

Please try this case:

Code: Select all

*abcd
* means a space

My AC code produce:

Code: Select all

00199897923
But your code just produce 2 blank lines.

Also, there are some problems in decoding.

your code cannot handle the number bigger than 99.

Such as:

Code: Select all

001
My AC code produce:

Code: Select all

d
However, your code did nothing but output 2 blank line.

I think you should use backtracking when you are decoding.

Hope that you can find the bug. :D

amine.hamdaoui
New poster
Posts: 10
Joined: Tue Aug 07, 2007 7:33 pm

Re: Why #444 WA?

Post by amine.hamdaoui » Wed Jul 22, 2009 11:53 pm

I tried a lot of test cases! All possibilities i know, but it gives me WA since 2 years! Can some one find the bug?

Code: Select all

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
    int i, a, size;
    string line, inv;

    while (getline(cin, line)) {
        size = line.size();
        if(size==0)
        {
            cout<<endl;
            continue;
        }
        if (line[0] < '0' || line[0] > '9') {
            for (i = size - 1; i >= 0; i--) {
                ostringstream osd;
                osd << (int) line[i];
                inv = osd.str();
                reverse(inv.begin(), inv.end());
                cout << inv;
            }
        } else {
            for (i = size - 1; i >= 0; i--) {
                ostringstream ose;
                if (line[i] != '1') {
                    a = (line[i - 1] - 48)*10 + line[i] - 48;
                    i--;
                } else {
                    a = (line[i - 2] - 48)*100 + (line[i - 1] - 48)*10 + line[i] - 48;
                    i = i - 2;
                }
                ose << a;
                inv = ose.str();
                reverse(inv.begin(), inv.end());
                istringstream iss(inv);
                iss >> a;
                switch (a) {
                    case 7: cout << 'F';
                        break;
                    case 8: cout << 'P';
                        break;
                    case 9: cout << 'Z';
                        break;
                    case 1: cout << 'd';
                        break;
                    case 11: cout << 'o';
                        break;
                    case 12: cout << 'x';
                        break;
                    default: cout << (char) a;
                        break;
                }
            }
        }
        cout << endl;
    }
    return 0;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: Why #444 WA?

Post by mf » Thu Jul 23, 2009 1:30 am

Maybe you should try to write a bit more clear and concise code? This table looks very suspicious to me, I wouldn't be surprised if you had a bug in there:

Code: Select all

                switch (a) {
                    case 7: cout << 'F';
                        break;
                    case 8: cout << 'P';
                        break;
                    case 9: cout << 'Z';
                        break;
                    case 1: cout << 'd';
                        break;
                    case 11: cout << 'o';
                        break;
                    case 12: cout << 'x';
                        break;
                    default: cout << (char) a;
                        break;
                }
Just rewrite that part of code from scratch in a more natural way, without any hard-coded tables like that.

samin_yasar
New poster
Posts: 5
Joined: Sat Mar 28, 2009 6:15 pm

Re: 444 - Encoder and Decoder

Post by samin_yasar » Thu Oct 22, 2009 8:03 pm

i m getting RT error.can anyone tell me why?

Code: Select all

#include <stdio.h>
#include <string.h>


int main()
{
	char msg[103];

	while(gets(msg))
	{
		int len = strlen(msg)-1;
		
		int temp=0;

		while(len>=0)
		{
		 if(msg[len]>='0' && msg[len]<='9')
		 {
			temp = (int)msg[len] - '0';
			
			if(len-1>=0)
			{
				temp = temp*10 + ((int)msg[len-1]-'0');

				printf("%c",temp);

				len-=2;

				if(len==0)
				{	
					temp = (int)msg[len]-'0';
					printf("%c",temp);
					len--;
				}
			}
			else if(len==1) 
			{
				temp = (int)msg[len--]-'0';
				printf("%c",temp);
				len--;
			}
		}
		 else
		 {
			 temp = msg[len];

			 while(temp!=0)
			 {
				 printf("%d",temp%10);
				 temp/=10;
			 }

			 len--;
		 }
			
		}
		printf("\n");
		
	}
	return 0;
}

mustafa.magdy
New poster
Posts: 1
Joined: Sat Nov 07, 2009 8:22 pm

Re: i got Runtime error in 444 !!! but why

Post by mustafa.magdy » Sat Nov 07, 2009 8:29 pm

any one believe that his code in perfect try to output those
07
08
09
001
011
021

sh415
New poster
Posts: 13
Joined: Fri Nov 13, 2009 9:31 am
Location: JU

Post by sh415 » Wed Sep 15, 2010 3:21 pm


You can assume a spy's message is at most 80 characters long, and it includes all the upper and lowercase letters of the alphabet plus the space, and any of the following characters:

! , . : ; ?
this is given in problem statement.

input may have other characters like " - "............. taking ascii 32 to 122 in account RE might be solved.....

SePulTribe
New poster
Posts: 28
Joined: Mon Nov 15, 2004 5:00 pm

Re: i got Runtime error in 444 !!! but why

Post by SePulTribe » Wed Dec 01, 2010 1:54 pm

This problem is lying. I had my input array at 100 before and it gave me RTE. I increased it to 1000 and it worked. Stupid.

Halum
New poster
Posts: 2
Joined: Wed Jul 06, 2011 9:30 pm

Re: i got Runtime error in 444 !!! but why

Post by Halum » Tue Jul 19, 2011 4:48 am

Yup.. get array size 1000 .. you wont get RTE. WTF is this.. stupid discription...

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

444 (Encoder Decoder) Why W A? Please, please help me

Post by uvasarker » Sun Nov 20, 2011 1:26 pm

I removed my post after AC.
But I provide some critical test cases for you. Just check these and get AC.
Sample Input:

Code: Select all

aefd
z?.: ;e
001201
Sample Output

Code: Select all

00120110179
1019523856436221
fd
Last edited by uvasarker on Sat Dec 31, 2011 5:52 am, edited 3 times in total.

Sawon90
New poster
Posts: 11
Joined: Wed Nov 23, 2011 1:28 am

Re: 444 (Encoder Decoder) Why I am getting W/A?? Please Help

Post by Sawon90 » Wed Nov 23, 2011 1:36 am

#include<stdio.h>
#include<string.h>
char st[1000000];
int main()
{
long i,ln,ch[300],a;
for(i=32;i<=122;i++)
{
a=i;
ch=0;
while(a>0)
{
ch=ch*10+a%10;
a=a/10;
}
}
while(gets(st))
{
ln=strlen(st);
if(st[0]>='0' && st[0]<='9')
{
a=0;
i=ln-1;
while(i>=0)
{
a=a*10+st-48;
if(a>=32)
{
printf("%c",a);
a=0;
}
i--;
}
}
else
{
for(i=ln-1;i>=0;i--)
printf("%ld",ch[st]);
}
printf("\n");
}
return 0;
}

Post Reply

Return to “Volume 4 (400-499)”