当前位置:网站首页>leetcode-168.Excel表列名称
leetcode-168.Excel表列名称
2022-07-23 13:03:00 【KGundam】
数学问题
题目详情
给你一个整数 columnNumber ,返回它在 Excel 表中相对应的列名称。
例如:
A -> 1
B -> 2
C -> 3
…
Z -> 26
AA -> 27
AB -> 28
…
示例1:
输入:columnNumber = 1
输出:"A"
示例2:
输入:columnNumber = 28
输出:"AB"
示例3:
输入:columnNumber = 701
输出:"ZY"
示例4:
输入:columnNumber = 2147483647
输出:"FXSHRXW"
思路:
很明显可以看出这是一道26进制转换问题,但是需要注意的是从1开始没有0
因为从1开始,所以我们可以对每个数减一操作,从而使126变成025
从而完全符合了26进制转换规则
我的代码:
class Solution
{
public:
string convertToTitle(int columnNumber)
{
string res;
while (columnNumber > 0)
{
--columnNumber; //整体减一
res += columnNumber % 26 + 'A'; //每次判断对应哪个字母然后接在后面(反的)
columnNumber /= 26;
}
reverse(res.begin(), res.end()); //反转得到正确结果
return res;
}
};
边栏推荐
- Niuke-top101-bm36
- 动态规划背包问题之多重背包详解
- The protection circuit of IO port inside the single chip microcomputer and the electrical characteristics of IO port, and why is there a resistor in series between IO ports with different voltages?
- 20220721 beaten content
- (已解决)idea编译Gradle项目提示 错误找不到符号
- 15001. System design scheme
- 【笔记】线性回归
- How to choose fluorescent dyes in laser confocal
- Frequently asked questions about MySQL
- 距7月30日PMP考试不足10天,应该做点什么?
猜你喜欢

中国化NFT?NFR横空出世

Study note 7 -- traffic environment behavior prediction

阿里平头哥CPU技术生态负责人陈炜:平头哥的发展之路

Surface family purchase reference

USB基础

48:第五章:开发admin管理服务:1:创建子工程【imooc-news-dev-service-admin】,管理服务模块;
![[C language] structure, enumeration and union](/img/18/3d9c511950cbcbd109df3104fbe248.png)
[C language] structure, enumeration and union

(resolved) idea compilation gradle project prompt error no symbol found

Dynamic programming knapsack problem 01 knapsack explanation

ts封装localstorage类,存储信息
随机推荐
Fastadmin, non super administrator, has been granted batch update permission, but it still shows no permission
MySQL multi table query_ Cartesian product_ Inner connection_ Implicit connection
AC automata and fail tree
实时疫情数据可视化分析
Bag of Tricks for Image Classification with Convolutional Neural Networks(卷积神经网络在图像分类中的技巧)
How to choose fluorescent dyes in laser confocal
Frequently asked questions about MySQL
TS encapsulates the localstorage class to store information
网络协议与攻击模拟:wireshark使用、ARP协议
AWS Part 1
ESP8266-NodeMCU——从苏宁API获取实时天气
Emgucv recording video
Life cycle, state management and local redrawing of fluent components | developers say · dtalk
Satisfiability of the equation of leetcode
16 automated test interview questions and answers
7月HCIP Datacom认证考试通过
go run,go build,go install有什么不同
【笔记】线性回归
Less than 10 days before the PMP Exam on July 30, what should be done?
Circuit structure and output mode of GPIO port of 32-bit single chip microcomputer