Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cctype>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- int N;
- char buf[1000];
- void Converti(int c) {
- int x=0, prec=0;
- while(prec + pow(26, x) <= c) {
- prec += pow(26, x);
- x++;
- }
- x--;
- for(; x>=0; x--) {
- prec -= pow(26, x);
- int t = (int)( (double)c / pow(26, x) );
- while(x > 0 && (c-(pow(26, x)*t)) < prec) t--;
- printf("%c", ('A' + (t-1)%26));
- }
- }
- int main() {
- scanf("%d", &N);
- for(int i=0; i < N; i++) {
- scanf("%s", buf);
- int r=0, c=0;
- if( sscanf(buf, "R%dC%d", &r, &c) == 2) { Converti(c); printf("%d\n", r); }
- else {
- r=0;
- c=0;
- for(int i=0; i < (int)strlen(buf); i++) {
- if(isdigit(buf[i])) r = r*10 + (buf[i] - '0');
- else c = c*26 + (buf[i] - 'A' + 1);
- }
- printf("R%dC%d\n", r, c);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement