Q- CodeChef: Practical coding for everyone
help me please why my code is giving runtime error…
here is my code link-:
https://www.codechef.com/viewsolution/36992491
Q- CodeChef: Practical coding for everyone
help me please why my code is giving runtime error…
here is my code link-:
https://www.codechef.com/viewsolution/36992491
Share the link to your submission.
Go to problems page->My Submissions
it will fail when one/some of the keys ‘U’, ‘L’, ‘R’, and ‘D’ is/are missing. For eg, if in the string, there is no ‘U’ character, calling m[‘U’] will raise runtime error, since the key won’t be there in the hashmap.
Intialize with U D L R all as 0
That does not cause a problem. It automatically return value as 0
It should be map<char,ll> not map<ll,ll>
Also, you do not need to use ll
Guys thanks for help-:
i changed map<char,int> m;
and it works
Why should we use like that. Characters can be represented as numbers right? Why is it giving Runtime error?
There’s no reason that I can see why using map<ll,ll> m;
should break things (it’s merely a weird thing to do :))
The actual problem seems to be this:
int t; cin>>t;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
i.e. calling sync_with_stdio
after reading input.
From here:
Thank you!
okay… thats the correct reason!! nice
If he uses key as ll
shouldn’t be also access keys with the ASCII code?
Yes - the char
should be implicitly converted to ll
which has the ASCII value of the char
, so I think it should work - at least, I can’t think of any situation where it shouldn’t.
hi… but what if we post the same solution in c++17 and not in c++14 ??
I am confused … is there any difference coz i submitted same soln in c++17 and it shows AC
There’s Implementation-defined Behaviour for you
Do you know how maps work?