题目翻译
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
给定一个正整数,返回其在一个excel列表中作为列序号时对应的列标题。
思路
用处理进制转换的一般思路,重复取模和除法即可。但是注意由于A对应1,所以Z之后是AA,这个转换不同于一般的进制转换。
chr()函数:返回0~255这个范围里面的整数的ASCii值。
代码
res = ‘’
while n:
res = chr((n-1)%26+65) + res
n = (n - 1) / 26
return res