FORGETPW - Editorial

I cracked this after trying different print techniques for the output.
First, I print the op as separate characters(i.e every single S[i] using loop). This didn’t work out. Secondly, I print the op as integers(using S[i]-‘0’ except for ‘.’). This didn’t work out as well. Finally after going through the solution of @pummy02(CodeChef: Practical coding for everyone) I got a hint. I assigned the 'last+1’th char as null and printed the op as a string. This worked out!

Can somebody help me with this solution, this gives correct answer for all the given tc but on submission gives wa.
https://www.codechef.com/viewsolution/14346300

@ar7thecoder you could have wrote it better. you are calculating leading and trailing zeroes for every string element which will give you a TLE. you can first decrypt the string and then calculate leading and trailing zeroes for the whole decrypted string. hope you get it now :slight_smile:

1 1 k l books not working for this test case, your code

did the test cases include many mappings to ‘.’ ??

1 Like

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

1 Like

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?

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 zHklFb - Online C Compiler & Debugging Tool - Ideone.com

In this line of your code(this can be a problem if your logic is correct…i haven’t checked yet…maybe there can be any other reason)

for(i=0;i<strlen(str);i++)
str[i]=arr[str[i]];

Here you are calculating the size of string in every iteration due to “strlen(str)” which is having time complexity of O(length(str)) making the time complexity of loop as O((length(str)) ^ 2)…
i was also getting TLE for same reason but thanks to a question on SPOJ and its forum that they told where I was making mistake

1 Like