Unnecessary Details: 1B — Spreadsheet [problem:1B] was extremely challenging for me; it took me over 2 hours to get AC. I didn't find the editorial helpful, and then when I went to see practice solutions from red/orange people, it made even less sense (they were basically copy/paste with minor variation of the following):
<spoiler summary="Solution">
~~~~~
#include<cstdio>
void g(int t){if(t){g((t-1)/26);putchar(65+(t-1)%26);}}
int main(){
int n,x,y;
char s[64],*p;
for(scanf("%d ",&n);n--;){
gets(s);
if(sscanf(s,"%*c%d%*c%d",&x,&y)==2){
g(y);
printf("%d\n",x);
}else{
for(x=0,p=s;*p>64;++p)
x=x*26+*p-64;
printf("R%sC%d\n",p,x);
}
}
return 0;
}
~~~~~
</spoiler>
I'll talk about each part of the problem itself and approaches/alternatives, and then explain how the above solution (henceforth "the solution") handles it. I'll go into unnecessary detail since I'm very new to CP/CF and would've wanted this...
. To make this explicit, we can try doing the normal conversion for decimal 494
, but we don't get the, Now converting 494 works correctly:, To make this explicit, we can try doing the normal conversion for decimal 494,
but we don't get the, ``` (12845-1) / 26 = 494 (12845-1) % 26 = 0 // 65 + 0 = 65, 'A' in ASCII (494
-1) / 26, ``` 494 / 26 = 19 494 % 26 = 0 // ?; we have no letter for 0 19 / 26 = 0 19 % 26, ``` 494 / 26 = 19 494 % 26 = 0 // Z 19 - 1 = 18 18 / 26 = 0 18 % 26 = 18 // R
Полный текст и комментарии »