Given a positive integer, return its corresponding column title as appear in an Excel sheet.
进制转化,其实质就是把数字转成26进制
由于1->A
, 2->B
, 26->Z
,即所以需要把n-1在操作
string convertToTitle(int n) {
string result;
while (n) {
result.push_back(--n % 26 + 'A');
n /= 26;
}
return string(result.rbegin(), result.rend());
}