Excel Sheet Column Title
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 res;
int i=1,k=0,m,j;
// while(i<=n)//当时这里报错是进行了两次循环
// {
// k++;
// i *= 26;
// }
// return res;
// while()
// for(j=0;j<k;j++)
//{
// m = n/(i/26);
// i=i/26;
// res += char('A'+m-1);
// n = n-m*i;
// }
// return res;
while(n>0)
{
i = (n-1)%26;
res = char('A'+i)+res;
n=(n-1)/26;
}
return res;
}
};
人生有些关口非狠狠的斗一下不可,不能为了混口饭吃而自甘蹉跎。

浙公网安备 33010602011771号