I’m just doing these for practice, but its really hard to call “.” a “positive decimal number”. Arguably its also hard to call “0” and “0.0” as a “positive decimal number” (“non-negative decimal number” would have been more appropriate), but I don’t think that “.” passes as a “positive decimal number” in any culture I’m aware of.
plz can anyone point out the error… 5l8Jy2 - Online C Compiler & Debugging Tool - Ideone.com
i spent lot of time over it…(>_<)
@m1sterzer0 after reading your answer above…out of curiosity i checked your submission for the problem… i dont know why its giving the wrong output instead of being accepted as right answer z1YyRR - Online C++ Compiler & Debugging Tool - Ideone.com
http://www.codechef.com/viewsolution/3999376
This is my solution it is passing every case mentioned in the problem and every corner case as well. What is the problem here?
I am getting wrong answer error… please help…
#include < iostream>
#include < string>
using namespace std;
int main()
{
int n;
cin>>n;
string enPass,Pass;
while(n>0)
{
int r,counter=0;
cin>>r; // no. of rules.
char c[r],p[r];
for(int i=0;i<r;i++)
{
cin>>c[i]>>p[i]; // taking each rule as input
}
cin>>enPass; // taking encrypted password as input
Pass = enPass;
for(int j=0;j<enPass.size();j++)
{
for(int s=0;s<r;s++)
{
if(c[s] == enPass[j])
{
Pass[j] = p[s];
}
}
}
int str_Size = Pass.size();
for(int q = str_Size-1; q >= 0; q--)
{
if(Pass[q] == '0') Pass.erase(q);
else if(Pass[q] == '.')
{
Pass.erase(q);
break;
}
else break;
}
for(int t=0;t<str_Size;t++)
{
if(Pass[t] == '0') counter++;
else break;
}
Pass.erase(0,counter);
cout<<Pass<<"\n";
n--;
}
return 0;
}
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 
1 1 k l books not working for this test case, your code
did the test cases include many mappings to ‘.’ ??
Shortest representation of 000.000 should be 0. Empty string can not be a valid representation.
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”)
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 