数字转表格标题 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;
}
};
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;
}
};
相关文章推荐
- 修改android应用包名
- 修改android应用包名
- umask命令
- 深入理解JavaScript系列(41):设计模式之模板方法
- 深入理解JavaScript系列(46):代码复用模式(推荐篇)
- 深入理解JavaScript系列(42):设计模式之原型模式
- LeetCode 234: Palindrome Linked List (回文链表)
- 修改android应用包名
- 修改android应用包名 分类: android 学习笔记 2015-07-16 22:48 4人阅读 评论(0) 收藏
- 关于stringWithFormat:
- 《JavaScript设计模式与开发实践》读书笔记之观察者模式
- 研究row_number和rank分析函数的区别
- at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)异常解决
- at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)异常解决
- at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)异常解决
- mysql备份以及我的备份文档
- PHP 使用GD库生成验证码 在图像上绘制汉字
- Linux下的定时器:alarm()与setitimer()
- 【计算机网络】知识点记录
- 欢迎使用CSDN-markdown编辑器