让我们看下面的实现以更好地理解-
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
string convertToTitle(int n) {
string res;
while(n){
res += (--n)%26 + 'A';
n /= 26;
}
reverse(res.begin(), res.end());
return res;
}
};
main(){
Solution ob;
cout << (ob.convertToTitle(30));
}30
输出结果
AD