首页 > 代码库 > leetcode 168

leetcode 168

168. 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 

给定一个正整数,返回它作为出现在Excel表中的正确列向标题。相当于26进制。
代码如下:
 1 class Solution { 2 public: 3     string convertToTitle(int n) { 4         string ss; 5         while(n > 0) 6         { 7             ss = (char)(--n % 26 + A) + ss; 8             n /= 26; 9         }10         return ss;11     }12 };

 



leetcode 168