Guest User

Untitled

a guest
Jan 25th, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<queue>
  5. #include<stack>
  6. #include<math.h>
  7. #include<vector>
  8. #include<map>
  9. #include<set>
  10. #include<stdlib.h>
  11. #include<cmath>
  12. #include<string>
  13. #include<algorithm>
  14. #include<iostream>
  15. #define exp 1e-10
  16. using namespace std;
  17.  
  18. const int N = 40001;
  19.  
  20. const int INF = 1e9;
  21.  
  22. const int MOD = 2009;
  23.  
  24. char s[N],w[4][N];
  25.  
  26. int main()
  27.  
  28. {
  29.  
  30. int t, i, j, k, r, c;
  31.  
  32. bool flag;
  33.  
  34. cin >> t;
  35.  
  36. while(t--)
  37.  
  38. {
  39.  
  40. memset(w,0,sizeof(w));
  41.  
  42. cin >> s;
  43.  
  44. for ( flag = true, k = i = j = 0; s[i] != '\0'; i++ )
  45.  
  46. {
  47.  
  48. if ( flag && s[i] >= '0' && s[i] <= '9' )
  49.  
  50. w[k][j] = '\0', k++, j = 0, flag = false;
  51.  
  52. else if( !flag && s[i] >= 'A' && s[i] <= 'Z' )
  53.  
  54. w[k][j] = '\0', k++, j = 0, flag = true;
  55.  
  56. w[k][j++] = s[i];
  57.  
  58. }
  59.  
  60. if ( k == 1 )
  61.  
  62. {
  63.  
  64. for ( r = c = i = 0; w[0][i] != '\0'; i++ )
  65.  
  66. c = c * 26 + w[0][i] - 'A' + 1;
  67.  
  68. for ( i = 0; w[1][i] != '\0'; i++ )
  69.  
  70. r = r * 10 + w[1][i] - '0';
  71.  
  72. printf("R%dC%d\n",r,c);
  73.  
  74. }
  75.  
  76. else if ( k == 3 )
  77.  
  78. {
  79.  
  80. for ( r = c = i = 0; w[3][i] != '\0'; i++ )
  81.  
  82. c = c * 10 + w[3][i] - '0';
  83.  
  84. i = 0;
  85.  
  86. while(c)
  87.  
  88. {
  89.  
  90. w[3][i++] = ( c - 1 ) % 26 + 'A';
  91.  
  92. c = ( c - 1 ) / 26;
  93.  
  94. }
  95.  
  96. for ( i--; i >= 0; i-- )
  97.  
  98. printf("%c",w[3][i]);
  99.  
  100. for ( i = 0; w[1][i] != '\0'; i++ )
  101.  
  102. r = r * 10 + w[1][i] - '0';
  103.  
  104. printf("%d\n",r);
  105.  
  106. }
  107.  
  108. }
  109.  
  110. exit(0);
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment