Leetcode 168 Excel Sheet Column Title 进制数转化

题意:将数字转化成excel表中的行中的项目

本质是10进制转化为26进制,但是在中间加入了一个不一样的操作,在每次操作前都需要n--

 1 class Solution {
 2 public:
 3     string convertToTitle(int n) {
 4         string s("");
 5         for(; n--; n/=26){
 6             s += string("A");
 7             s[s.size() - 1] += n% 26; 
 8         }
 9         reverse(s.begin(),s.end());
10         return s;
11     }
12 }
原文地址:https://www.cnblogs.com/onlyac/p/5497627.html