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
从26进制转换到10进制,
class Solution { public: int titleToNumber(string s) { int n = s.length(); int t = 1, x, sum = 0; for (int i = n - 1; i >= 0; --i) { x = (s[i] - 'A') + 1; x *= t; sum += x; t *= 26; } return sum; } };
原文地址:http://www.cnblogs.com/pk28/
与有肝胆人共事,从无字句处读书。
欢迎关注公众号:
欢迎关注公众号:
浙公网安备 33010602011771号