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
思路:进制之间的转化,不过这里需要考虑的是这里没有0这个数,不过可以模26,然后对于结果是0的看做26.
string convertToTitle(int n) { string result; int num = n; int temp; while(num) { temp = num%26; temp = temp ==0? 26:temp; result += (temp+'A'-1); num = (num-temp)/26; } reverse(result.begin(),result.end()); return result; }
Excel Sheet Column Number--LeetCode
原文地址:http://blog.csdn.net/yusiguyuan/article/details/45008373