Advertisement
Guest User

1B - Spreadsheet (WA test 6, don't know why)

a guest
Jun 29th, 2014
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cctype>
  4. #include <cstdio>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. int N;
  9. char buf[1000];
  10.  
  11. void Converti(int c) {
  12.     int x=0, prec=0;
  13.     while(prec + pow(26, x) <= c) {
  14.         prec += pow(26, x);
  15.         x++;
  16.     }
  17.     x--;
  18.     for(; x>=0; x--) {
  19.         prec -= pow(26, x);
  20.         int t = (int)( (double)c / pow(26, x) );
  21.         while(x > 0 && (c-(pow(26, x)*t)) < prec) t--;
  22.         printf("%c", ('A' + (t-1)%26));
  23.     }  
  24. }
  25.  
  26. int main() {
  27.     scanf("%d", &N);
  28.     for(int i=0; i < N; i++) {
  29.         scanf("%s", buf);
  30.         int r=0, c=0;
  31.         if( sscanf(buf, "R%dC%d", &r, &c) == 2) { Converti(c); printf("%d\n", r); }
  32.         else {
  33.             r=0;
  34.             c=0;
  35.             for(int i=0; i < (int)strlen(buf); i++) {
  36.                 if(isdigit(buf[i])) r = r*10 + (buf[i] - '0');
  37.                 else c = c*26 + (buf[i] - 'A' + 1);
  38.             }
  39.             printf("R%dC%d\n", r, c);
  40.         }
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement