Advertisement
LuftAffe

1B

Aug 28th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <math.h>
  5.  
  6. int r, c;
  7.  
  8. bool is_digit(char c){
  9.     return c >= '0' && c <= '9';
  10. }
  11.  
  12. bool is_alpha(char c){
  13.     return c >= 'A' && c <= 'Z';
  14. }
  15.  
  16. int ltd(char c, int p){
  17.     int tp = c - '0';
  18.     while(p--)
  19.         tp *= 10;
  20.     return tp;
  21. }
  22.  
  23. bool is_exl_format(char* s, int n){
  24.     bool tmp = false;
  25.     for(int i = 0; i < n; i++){
  26.         tmp |= is_digit(s[i]);
  27.         if(tmp && s[i] == 'C')
  28.             return false;
  29.     }
  30.     return true;
  31. }
  32.  
  33. void dtw(int a){
  34.     char s[30];
  35.     int it = 0;
  36.     while(a){
  37.         a--;    
  38.         s[it++] = a % 26 + 'A';
  39.         a /= 26;
  40.     }
  41.     for(int i = it-1; i >= 0; --i)
  42.         printf("%c", s[i]);
  43. }
  44.  
  45. int wtd(char* os, int b, int e){
  46.     char s[30];
  47.     memcpy(s, os, e);
  48.     s[e] = 0;
  49.     return atoi(s + b);
  50. }
  51.  
  52. void f1(char* s, int n){
  53.     int e;
  54.     for(e = 1; s[e] != 'C'; ++e){
  55.     }
  56.     r = atoi(s + 1);
  57.     c = wtd(s, e+1, n);
  58.     dtw(c);
  59.     printf("%d\n", r);
  60. }
  61.  
  62. int ff(char *s, int e){
  63.     int a = 0;
  64.     int p = e-1;
  65.     for(int i = 0; i < e; ++i){
  66.         a += (s[i] - 'A' + 1) * (int)pow(26 * 1.0, p);//
  67. //        printf("\ns[i] - 'A' + 1 = %d||pow = %d\n", s[i] - 'A' + 1, (int)pow(26 * 1.0, p));
  68.         p--;
  69.  
  70.     }
  71.     return a;
  72. }
  73.  
  74. void f2(char* s, int n){
  75.     int e = 0;
  76.     for(; is_alpha(s[e]); ++e){}
  77.  
  78.     printf("R%dC%d\n", atoi(s + e), ff(s, e));
  79. }
  80.  
  81. int main(){
  82. /*
  83.     freopen("input.txt", "r", stdin);
  84.     freopen("output.txt", "w", stdout);
  85. */
  86.     int n;
  87.     int size;
  88.     scanf("%d", &n);
  89.     char s[30];
  90.     while(n--){
  91.         scanf("%s", s);
  92.         size = strlen(s);
  93.         if(is_exl_format(s, size)){
  94.             f2(s, size);
  95.         }
  96.         else
  97.             f1(s, size);
  98.     }
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement