spider68

excel sheet

Jul 1st, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int i,t,n;
  7.     cin>>t;
  8.     while(t--)
  9.     {
  10.         cin>>n;
  11.         string s="";
  12.         while(n>0)
  13.         {
  14.             i=n%26;
  15.             if(i==0){s+='Z'; n--;}
  16.             else s+='A'+i-1;
  17.             n/=26;
  18.         }
  19.         reverse(s.begin(),s.end());
  20.         cout<<s<<endl;
  21.     }
  22.     return 0;
  23. }
  24. ------------
  25. int titleToNumber(string s)
  26. {
  27.     int result = 0;
  28.     for (const auto& c : s)
  29.     {
  30.         result *= 26;
  31.         result += c  - 'A' + 1;
  32.     }
  33.     return result;
  34. }
Add Comment
Please, Sign In to add comment