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
class Solution {
public:
string convertToTitle(int n) {
string ret, str;
if(n < 0) return ret;
while(n)
{
int tmp = n % 26;
n /= 26;
if(tmp == 0)
{
str += 'Z';
n--;
}
else
{
str += 'A' + tmp - 1;
}
}
for(int i = str.size()-1; i >= 0; i--)
{
ret += str[i];
}
return ret;
}
};