Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
Show Tags
Have you met this question in a real interview? Yes No
For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
Show Tags
Have you met this question in a real interview? Yes No
Discuss
这道题目和前面一题相对应这里依然可以当成26进制来做。
代码如下
def convert(num):
result=''
while num>0:
rest=(num-1)%26
result=chr(rest+65)+result
num=(num-1)/26
return result
def main():
num=27
#print chr(64)
print convert(num)
if __name__=="__main__":
main()