Can someone tell me why the below solution is giving Run time error.
https://www.codechef.com/viewsolution/27919892
Any help would be appreciated !!
Can someone tell me why the below solution is giving Run time error.
https://www.codechef.com/viewsolution/27919892
Any help would be appreciated !!
Line 83 gives the error
Changing it to:
int val=((s[i]-‘A’) - (k%26) + 26)%26;
if(val<0)
{
val=(val+26)%26;
}
removes it
Don’t mind it but how come
int val=((s[i]-‘A’) - (k%26) + 26)%26;
val can be negative here?
s[i]-‘A’ = 0,1,2…25
k%26 = 0,1,2,…25
(s[i]-‘A’ - (k%26)) = -25,-24…25
(s[i]-‘A’ - (k%26) + 26) = 1,2,3,…25+26
(s[i]-‘A’- (k%26) + 26)%26 = 0,1,2,…25
I don’t think that val can ever be negative.
Thanks, correct me if I am wrong.