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
answer:
class Solution { public: int titleToNumber(string s) { int res=0,i,n=s.length(),k=1; char a; //return n; for(i=n-1;i>=0;i--) { // return i; a = s[i]; res = res + (int(a-'A') + 1) * k ; k *= 26; } return res; } };
人生有些关口非狠狠的斗一下不可,不能为了混口饭吃而自甘蹉跎。