[LeetCode]168. Excel Sheet Column Title

来源:互联网 发布:淘宝客定向计划审核 编辑:程序博客网 时间:2024/06/18 11:01

[LeetCode]168. Excel Sheet Column Title

题目描述

这里写图片描述

思路

类似于进制转换

代码

#include <iostream>#include <string>using namespace std;class Solution {public:    string convertToTitle(int n) {        string convert = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", res = "";        n = n - 1;        while (n >= 0) {            res = convert[n % 26] + res;            n = n / 26 - 1;        }        return res;    }};int main() {    Solution s;    cout << s.convertToTitle(26) << endl;    cout << s.convertToTitle(27) << endl;    cout << s.convertToTitle(52) << endl;    cout << s.convertToTitle(53) << endl;    system("pause");    return 0;}
原创粉丝点击