[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;
}