Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Weird result when using map in June14 question "Forgot Password"

$
0
0

For this question, I first used a map<char,char> for doing the replacement according to the rules.

map<char,char> m;
m[ci] = pi;

Did not work. After a lot of struggling, I finally thought of doing asserts to check whether the final string I'm getting is actually a decimal number. So I counted number of dots '.' and that assert failed.

assert(dots <= 1);

( http://www.codechef.com/viewsolution/4121506 )

I couldn't get AC, so I thought of just using a char array to do the same mapping from ci -> pi

char m[1000];
memset(m,' ',1000);
m[ci] = pi;

( http://www.codechef.com/viewsolution/4121511 )

Surprisingly this worked. Those two solutions differ at only 3 lines ( line #13, #18, #30). Can someone tell me what's wrong with the map<char,char> solution?


Viewing all articles
Browse latest Browse all 39796

Trending Articles