您的位置:首页 > 编程语言 > PHP开发

将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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c excel output input header wap
相关文章推荐