标签:leetcode
@author:wepon
@blog:http://blog.csdn.net/u012162613
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;
while(n){
int r=n%26;
n=n/26;
if(r==0){ //为26的整数倍,该位设置为Z,n减掉1
str+='Z';
n--;
}else{
str+=('A'+r-1);
}
}
//反转
string result;
for(int i=str.size()-1;i>=0;i--){
result+=str[i];
}
return result;
}【leetcode 进制转换】Excel Sheet Column Title
标签:leetcode
原文地址:http://blog.csdn.net/u012162613/article/details/42059591