您的位置:首页 > 其它

数字转表格标题 Excel Sheet Column Title

2015-07-16 22:49 169 查看
#include<string>
using namespace std;
class Solution {
public:
string convertToTitle(int n) {
string res;
if(n<=0) return "";
  while(n)
    {
      res+=(n-1)%26+'A'; //[n-1]这里一定要想明白了,注意头尾两个数据的验证
      n=(n-1)/26;
    }
    reverse(res.begin(),res.end());
    return res;
  }
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: