/*
* Leetcode168. Excel Sheet Column Title
* Funtion: Given a positive integer, return its corresponding column title as appear in an Excel sheet.
* Example: 1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
* Author: LKJ
* Date:2016/7/26
*/
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
string convertToTitle(int n) {
string str;
string tem;
while(n){
tem = 'A' + (n-1)%26;
str = tem+str;
n = (n-1)/26;
}
return str;
}
};
int main(){
int myin;
string myout;
Solution SA;
cout << "Please Enter" << endl;
cin >> myin;
myout = SA.convertToTitle(myin);
cout << myout << endl;
return 0;
}
LeetCode 简单操作 | 168. Excel Sheet Column Title
最新推荐文章于 2020-08-16 22:05:40 发布