Advertisement
AyAks69

Spreadsheet -1600

Oct 31st, 2022
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ios_base::sync_with_stdio(false);
  10.     cin.tie(NULL);
  11.  
  12.     #ifndef ONLINE_JUDGE
  13.     freopen("input.txt","r",stdin);
  14.     freopen("output.txt","w",stdout);
  15.     #endif
  16.  
  17.     int t;
  18.     cin >> t;
  19.     while(t--)
  20.     {
  21.         string s;
  22.         cin >> s;
  23.  
  24.         bool is_sec=false;
  25.         size_t pos_c = s.find_first_of('C');
  26.         if(s[0]=='R')
  27.         {
  28.             if(pos_c!=std::string::npos)
  29.             {
  30.                 string t = s.substr(1,pos_c-1);
  31.                 sort(t.begin(),t.end());
  32.                 if((0<=t[0])&&(t[0]<='9'))
  33.                 {
  34.                     is_sec = true;
  35.                 }
  36.             }
  37.         }
  38.  
  39.         if(is_sec)
  40.         {
  41.             string s2="";
  42.             int r = std::stoll(s.substr(1,pos_c-1));
  43.             int c = std::stoll(s.substr(pos_c+1,s.size()-1-pos_c));
  44.             while(c)
  45.             {
  46.                 int rem = c%26;
  47.                 if(rem)
  48.                 {
  49.                     s2 = (char)(rem+64)+s2;
  50.                     c/=26;
  51.                 }
  52.                 else
  53.                 {
  54.                     s2 = "Z" +s2;
  55.                     c/=26;
  56.                     c--;
  57.                 }
  58.  
  59.             }
  60.             cout << s2;
  61.             cout << r <<"\n";
  62.         }
  63.         else
  64.         {
  65.             int num;
  66.             for(int i=0; i< s.size();i++)
  67.             {
  68.                 if((0<=s[i])&&(s[i]<='9'))
  69.                 {
  70.                     num=i;
  71.                     break;
  72.                 }
  73.             }
  74.             cout << "R" << s.substr(num,s.size()-num)<<"C";
  75.             int sum,n=num-1;
  76.             sum=0;
  77.             for(int i=0; i<num; i++)
  78.             {
  79.                 sum=sum+ (s[i]-64)*pow(26,n);
  80.                 n--;
  81.             }
  82.             cout << sum << "\n";
  83.         }
  84.     }
  85.      return 0;
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement