Excel Sheet Column Title 分类: Leetcode 2015-01-15 11:08 87人阅读 评论(0) 收藏

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 

十进制转换为二十六进制,其中n--是很关键的一步

class Solution {
public:
    string convertToTitle(int n) {
        int i,j,mod;
        string s;
        char num;
        while(n>0)
        {
            n--;
            mod=n%26;
            num='A'+mod;
            s=num+s;
            n=n/26;
        }
        return s;
    }
};


版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/learnordie/p/4656974.html