一、题目要求
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
二、代码实现
string convertToTitle(int n) {
string str;
int tmp;
while(n)
{
tmp=n%26;
n/=26;
if(tmp)
str.push_back(tmp-1+'A');
else
{
str.push_back('Z');
n--;
}
}
if(str.size()>1)
reverse(str.begin(),str.end());
return str;
}