FORGETPW - Editorial

Shortest representation of 000.000 should be 0. Empty string can not be a valid representation.

1 Like

A small correction, 0. and . themselves hold no meaning, as the question itself suggests that

After all the character replacements, the string is guaranteed to be a positive decimal number.

my all test cases are working properly and have checked each and every possibility of test case that can be possible but it is still showing wrong answer.
Here is my code. please someone go through it and help me out.

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

int main()
{
int t,n,i,j,a,k,e,d,flag,flag1,b;
char s[1000001],c[127],p[127],m[1000001];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf(" %c %c",&c[i],&p[i]);
}
scanf("%s",s);
flag=0;
flag1=2;
a=strlen(s);
if(n!=0)
{
for(i=0;i<a;i++)
{
for(j=0;j<n;j++)
if(s[i]==c[j])
{
s[i]=p[j];
break;
}
}
	}
for(i=0;i<=a;i++)
{ if(s[i]>'0' && flag==0)
{
flag=1;
j=i;
}
if(s[i-1]>'0' && s[i]=='0')
k=i-1;
else if(s[i-1]>'0' && s[i]=='\0')
k=i;
if(s[i]=='.' && flag==0)
{ flag1=0;
e=i;
}
if(s[i]=='.' && flag==1)
{ d=i;
flag1=1;
}
}
if(flag1==2)
{
for(i=j;i<a;i++)
m[i-j]=s[i];
}
else if(flag==1 && flag1==1)
{
if(k>d)
for(i=j;i<=k;i++)
m[i-j]=s[i];
else
for(i=j;i<d;i++)
m[i-j]=s[i];
}
else
{
for(i=e;i<=k;i++)
m[i-e]=s[i];
}
if(flag!=1)
printf("0\n");
else
printf("%s\n",m);
b=strlen(m);
for(i=0;i<b;i++)
m[i]='\0';
	for(i=0;i<n;i++)
c[i]='\0';
	for(i=0;i<n;i++)
p[i]='\0';
}

return 0;
}

and it was a decimal number ultimately…

i think your case is not covering for the test case 000000000000 or 00000.000

just after one replacement flag them like for str[i] u have done replacement then take another bool array foo[100000] and at foo[i] make it equal to 1 and at the end of the loop again initialise all elements of array foo = 0;

you have not used newline in printf as"\n" like for printf(“0”) u have to write like printf(“0\n”)

1 Like

what is your output for test case 1: 0
case 2 : 000000000000000000000

The question says shortest representation for 0.5 is .5 and for 5.0 it is 5. The question didn’t mention about any order that we have to follow… So keeping both things in mind how can shortest representation of 0.0 be 0

@minato_namikaz:
1
0
00.
the o/p should be “0”. ur code prints ‘.’ - it is not a valid decimal number…

@rkm123:
Ur program works fine when there is only 1 test case… but when 2 or more are given… the results are wrong.
2
3
0 .
. 9
5 0
95.0
0
01800
try the above one… You will understand where you went wrong :slight_smile:

@brobear1995
1 1 k l
Where is the encrypted string?

Check this…It works perfect. Give all the required solution.
But give wrong ans.

http://www.codechef.com/viewsolution/4065063

I am getting Runtime error for my java code.
Can anybody help me with this?

http://www.codechef.com/viewsolution/4044062

http://www.codechef.com/viewsolution/4110336
Can you please tell me for what case does this solution fail because it passes all the tricky cases mentioned here.
Thanks in advance.

what are you getting for test case 00.00100 ?
once try to check it

@brobear1995 okay i understood that encrypted string is books.
but it was clearly mentioned in the problem “After all the character replacements, the string is guaranteed to be a positive decimal number.”
So as far as I understood, Test cases should be such that, after replacements it will be giving a decimal number.
Please correct me if i’m wrong.

4 Likes

its gives 0… gives correct for tricky and normal tests… the tested program is up on ideone link provided

it is showing runtime error in ideone see here http://ideone.com/zHklFb

we can also used linked list for removing 0