leetcode 171. Excel Sheet Column Number
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
AC:
int titleToNumber(char* s) {
int len=strlen(s);
int result=0;
for(int i=0;i<len;i++)
{
int para=1;
for(int j=0;j<i;j++)
{
para*=26;
}
result+=(s[len-1-i]-'A'+1)*para;
}
return result;
}
tips:输入zyx 输出 result=x*26^0+y*26^1+z*26^2