Excel列表字母数字转换

给定一个Excel表格中的列名称,返回其相应的列序号

例如,

A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28 
...

26进制

int titleToNumber(string s) {
        if(s.size()==0)
        return 0;
    int len = s.size();
    int res =0;
    for(int i=0; i<len;i++){
        int cur= s[i]-'A' +1;
        res = res * 26 + cur;

    }
    return res;
    }

给定一个正整数,返回它在 Excel 表中相对应的列名称

例如,

1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB 
...
string convertToTitle(int n) {
        string ans = "";
        while (n > 0)
        {
            n -= 1;
            ans.push_back('A' + (n % 26));
            n /= 26;
        }
        reverse(ans.begin(), ans.end());
        return ans;
    }