Wednesday, 7 March 2018

Hell yeah !!! A day long 1B- Spreadsheet

1B-spreadsheet

Ref : http://codeforces.com/problemset/problem/1/B

First, I didnt get AC jz coz  of some mysterious unknow off-by one error i can say...!
Here's my unaccepted code : 
while(C > 0){
                int x = 0;
                x = (C-1)%26;
                if(x == 0){
                 ans[i++] = 'Z';
                }
                else{
                    ans[i++] = 'A'+x-1;
                }
                C = (C-1)/26;
            }

Actually, I found that my logic is wrong :/
But when  I changed it to this, It got accepted : 

while((C-1)/26){
ans[i++] = (C-1)%26+'A';
C = (C-1)/26;
}
ans[i++] = (C-1)%26+'A';

No comments:

Post a Comment