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
思路:就是将十进制转化为26进制。注意在ret = char((n - 1) % 26 + 'A') + ret,只能将ret加在后面,起到字符串连接的作用。
class Solution { public: string convertToTitle(int n) { string ret = ""; while(n) { ret = char((n - 1) % 26 + 'A') + ret; n = (n - 1) / 26; } return ret; } };