美文网首页
171. Excel Sheet Column Number

171. Excel Sheet Column Number

作者: YellowLayne | 来源:发表于2017-06-23 10:32 被阅读0次

    1.描述

    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
    

    2.分析

    3.代码

    int titleToNumber(char* s) {
        if (NULL == s) return 0;
        int colnum = 0;
        unsigned int length = strlen(s);
        for (unsigned int i = 0 ;i < length; ++i) {
            colnum = colnum * 26 + s[i] - 'A' + 1;
        }
        return colnum;
    }
    

    相关文章

      网友评论

          本文标题:171. Excel Sheet Column Number

          本文链接:https://www.haomeiwen.com/subject/lgzqcxtx.html