Surface Pro 3看起来不错# PDA - 掌中宝
k*t
1 楼
给你26个字母,从A-Z, 用大小为26的数组letters存放。 input为一个integer,
output为一个string. 举例如下:
input->output
0 -> A
1 -> B
2 -> C
.......
25 -> Z
26 -> AA
27 -> AB
........
51 -> AZ
676 -> AAA
677 -> AAB
..........
我用的方法就是%, /. 但遇到比较tricky的问题就是最后当input为小于26时,我要减1
,再取对应的character. 比如: input为52, 52%26 == 0, letters[0] = 'A', 当前结
果为“A”,然后update52/26=2, 用2%26==2, letter[2] == 'C', append 'C' into
the head of the string, it would be wrong as the result is "CA" while the
correct result should be "BA". 但是有些case, 比如input是675时,我写的算法是
对的。感觉绕进去出不来了。
output为一个string. 举例如下:
input->output
0 -> A
1 -> B
2 -> C
.......
25 -> Z
26 -> AA
27 -> AB
........
51 -> AZ
676 -> AAA
677 -> AAB
..........
我用的方法就是%, /. 但遇到比较tricky的问题就是最后当input为小于26时,我要减1
,再取对应的character. 比如: input为52, 52%26 == 0, letters[0] = 'A', 当前结
果为“A”,然后update52/26=2, 用2%26==2, letter[2] == 'C', append 'C' into
the head of the string, it would be wrong as the result is "CA" while the
correct result should be "BA". 但是有些case, 比如input是675时,我写的算法是
对的。感觉绕进去出不来了。