[leetcode] 171. Excel Sheet Column Number

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 
class Solution {
public:
    int titleToNumber(string s) {
        int n=s.length();
        int i,sum=0;
        for(i=0;i<n;i++)
        {
            sum=sum*26+ s[i]-64;
        }
        return sum;
    }
};

A的ascii: 65

posted @ 2016-03-21 10:25  白天黑夜每日c  阅读(118)  评论(0编辑  收藏  举报