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 

其实类似26进制数

class Solution {
public:
    string convertToTitle(int n) {
        string  s = "";
        while (n > 0) {
            int y = --n%26 ;
            n /= 26;
            s = char(y + 'A') + s;
        }
        return s;
    }
};

 

posted on 2017-07-26 07:58  Beserious  阅读(130)  评论(0编辑  收藏  举报