Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<queue>
- #include<stack>
- #include<math.h>
- #include<vector>
- #include<map>
- #include<set>
- #include<stdlib.h>
- #include<cmath>
- #include<string>
- #include<algorithm>
- #include<iostream>
- #define exp 1e-10
- using namespace std;
- const int N = 40001;
- const int INF = 1e9;
- const int MOD = 2009;
- char s[N],w[4][N];
- int main()
- {
- int t, i, j, k, r, c;
- bool flag;
- cin >> t;
- while(t--)
- {
- memset(w,0,sizeof(w));
- cin >> s;
- for ( flag = true, k = i = j = 0; s[i] != '\0'; i++ )
- {
- if ( flag && s[i] >= '0' && s[i] <= '9' )
- w[k][j] = '\0', k++, j = 0, flag = false;
- else if( !flag && s[i] >= 'A' && s[i] <= 'Z' )
- w[k][j] = '\0', k++, j = 0, flag = true;
- w[k][j++] = s[i];
- }
- if ( k == 1 )
- {
- for ( r = c = i = 0; w[0][i] != '\0'; i++ )
- c = c * 26 + w[0][i] - 'A' + 1;
- for ( i = 0; w[1][i] != '\0'; i++ )
- r = r * 10 + w[1][i] - '0';
- printf("R%dC%d\n",r,c);
- }
- else if ( k == 3 )
- {
- for ( r = c = i = 0; w[3][i] != '\0'; i++ )
- c = c * 10 + w[3][i] - '0';
- i = 0;
- while(c)
- {
- w[3][i++] = ( c - 1 ) % 26 + 'A';
- c = ( c - 1 ) / 26;
- }
- for ( i--; i >= 0; i-- )
- printf("%c",w[3][i]);
- for ( i = 0; w[1][i] != '\0'; i++ )
- r = r * 10 + w[1][i] - '0';
- printf("%d\n",r);
- }
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment