码迷,mamicode.com
首页 > 其他好文 > 详细

168 Excel Sheet Column Title Excel表列名称

时间:2018-04-07 01:08:25      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:des   div   参考   res   public   class   desc   post   problem   

给定一个正整数,返回它在Excel表中相对应的列名称。
示例:
    1 -> A
    2 -> B
    3 -> C
    ...
    26 -> Z
    27 -> AA
    28 -> AB

详见:https://leetcode.com/problems/excel-sheet-column-title/description/

class Solution {
public:
    string convertToTitle(int n) {
        string res="";
        while(n)
        {
            res=char((n-1)%26+‘A‘)+res;
            n=(n-1)/26;
        }
        return res;
    }
};

 参考:https://www.cnblogs.com/ganganloveu/p/4175848.html

168 Excel Sheet Column Title Excel表列名称

标签:des   div   参考   res   public   class   desc   post   problem   

原文地址:https://www.cnblogs.com/xidian2014/p/8729437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!