1.描述
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
2.分析
3.代码
int titleToNumber(char* s) {
if (NULL == s) return 0;
int colnum = 0;
unsigned int length = strlen(s);
for (unsigned int i = 0 ;i < length; ++i) {
colnum = colnum * 26 + s[i] - 'A' + 1;
}
return colnum;
}