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 str;
int carry = 0;
int result = 0;
char c[2];
c[1] = '\0';
while(n>26){
carry = n%26;
if(carry == 0){
c[0] = 'Z';
n = n-26;
}else{
c[0] = carry + 'A'-1;
}
str = string(c) + str;
n = n/26;
}
if(n!=0){
c[0] = n + 'A' - 1;
str = string(c) + str;
}
return str;
}
};