一些算法记录
作者:
十月末的故事 | 来源:发表于
2019-05-08 09:29 被阅读0次1. 将十进制数字转换为26个字母代号。 必须从1开始。 1=A,26=Z。 27=AA,52=AZ。
此问题相当于将10进制数字转换为26进制的数字
+ (NSString *)getColumnName:(NSInteger)columnNumber
{
NSInteger colNum = columnNumber;
if (colNum < 1) {
return nil;
}
NSMutableString *colName = [NSMutableString string];
while (colNum > 0)
{
char cstr = (char)('A' + (colNum - 1) % 26);
[colName insertString:[NSString stringWithFormat:@"%c", cstr] atIndex:0];
colNum = (colNum - 1) / 26; // 减 1 因避免被 26 的倍数整除
}
return colName;
}
本文标题:一些算法记录
本文链接:https://www.haomeiwen.com/subject/vxvpoqtx.html
网友评论