https://leetcode.com/problems/excel-sheet-column-title/
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
其实就是10进制转26进制。但是存在一个细节问题,就是每一位的计算应先将n-1,比如计算26:(--26)%26+65=90
string convertToTitle(int n)
{
string res = "";
char c;
while (n > 0)
{
c = (char)(--n % 26 + 'A');
res = c + res;
n /= 26;
}
return res;
}
递归
string convertToTitle(int n)
{
if (n == 0)
return "";
return convertToTitle(n/26)+ (char)(--n % 26 + 'A');
}