1.题目
https://leetcode-cn.com/problems/excel-sheet-column-title/description/
2.思路
把数字/26像进制转化一样操作
3.代码
string convertToTitle(int n){
string str="";
int i,j=0;
while(n)
{
i=(n-1)%26;
str+='A'+i;
n=(n-1)/26;
}
reverse(str.begin(),str.end());
for(int i=0;i<str.length();i++)
cout<<str[i];
return str;
}
4.参考
class Solution {
public:
string convertToTitle(int n) {
string s;
while(n){
s += (n-1)%26+'A';
n = (n-1)/26;
}
reverse(s.begin(), s.end());
return s;
}
};