将A, B, C , D ... Z, AA, AB...AZ, BA转换为对应的数字
2012-07-24 11:52
483 查看
/* WAP to return numbered index if input is excel sheet column header name. e.g excel sheet column headers are A, B, C , D ... Z, AA, AB...AZ, BA,, etc if Input is D , output should be 4 and for AA output should be 27 */ #include <cstdio> #include <cstdlib> #include <cstring> int main() { char* str = "B"; char base = 'A' - 1; int idx = strlen(str) - 1; int num = 0; int mulFactor = 1; while(idx >= 0) { num += (str[idx] - base) * mulFactor; mulFactor *= 26; idx--; } printf("%s = %d", str, num); return 0; }
相关文章推荐
- 已知:yi er san si wu liu qi ba jiu 分别对应 123456789,对一段只含 有这几种字符的字符串进行转换,转换成相应的数字
- 26字母转换成数字,26进制,a为1,aa为27,ab为28
- 已知:yi er san si wu liu qi ba jiu 分别对应123456789,对一段只含有这几种字符的字符串进行转 换,转换成相应的数字
- Python Cookbook 第二版 汉化版 [Recipe 1.2] 字符与其对应的数字编码之间的转换
- 【c语言】编写一个函数,将一个数字字符串转换成该字符串对应的数字(包括正整数、负整数)
- 将数字转换为对应的字符 c++
- 数字和其对应的字符串之间转换的规律
- int my_atof(char *str) 将一个数字字符串转换成该字符串对应的数字(包括正整数、负整数)
- 为函数原型编写函数定义:int my_atoi(char *str);(将一个数字字符串转换成该字符串对应的数字(包括正整数、负整数))
- 编写一个函数,将一个数字字符串转换成这个字符串对应的数字(包括正浮点数、负浮点数) 例如:“12.34“ 返回12.34 “-123.34“ 返回-123.34 函数原型:double my_
- 数字 0 - 9 转换成对应的格雷码
- java将金额数字转换成对应的汉字
- C语言将字符串转换成对应的数字(十进制、十六进制)
- 把数字日期里的"月份"单独拿出来转换成对应的汉字月份
- 编写一个函数,将一个数字字符串转换成该字符串对应的数字(包括正整数、负整数) 例如:“12“ 返回12 “-123“ 返回-123 函数原型:int my_atoi(char *str) {}
- 用c语言实现 编写一个函数,将一个数字字符串转换成这个字符串对应的数字(包括正浮点数、负浮点数)
- 将数字金额转换为对应的中文大写金额
- javaweb中把数字转换成对应图片的方法
- 让字母自增,就像A-Z,Z后面就是AA-AZ,然后BA-BZ...
- 将一个数字字符串转换成这个字符串对应的数字包括正浮点数、负浮点数)