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 -> AA28 -> AB
class Solution {
public:
string convertToTitle(int n) {
map<int, char> sheetset;
string result = "";
int pointer;
for (int i = 1; i <= 26; i++)
{
sheetset[i] = 'A' + i - 1;
}
while (n>0)
{
if (n % 26 == 0)
{
pointer = 26;
n = n - 26;
}
else
pointer = n % 26;
result = result + sheetset[pointer];
n = n / 26;
}
for (int j = 0; j<result.length() / 2; j++)
{
char tmp = result[j];
result[j] = result[result.length() - 1 - j];
result[result.length() - 1 - j] = tmp;
}
return result;
}
};