leetcode-Excel Sheet Column Title

题目链接:https://leetcode.com/problems/excel-sheet-column-title/

代码如下:

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

 

posted @ 2016-05-29 14:20  Shirley_ICT  阅读(139)  评论(0编辑  收藏  举报