zoukankan      html  css  js  c++  java
  • Excel Sheet Column Number(STRING-TYPE CONVERTION)

    QUESTION

    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

    FIRST TRY

    string与数字的转换要借助char

    class Solution {
    public:
        int titleToNumber(string s) {
            int ret = 0;
            char ch;
            for(int i = 0; i < s.length(); i++)
            {
                ch = s[i]; //string to char
                ret = ret*26 + ch - 'A' + 1;
            }
            return ret;
        }
    };
  • 相关阅读:
    Google 嘘! 嘘!
    zabbix fast
    zabbix
    kernel update
    列表推导
    Ddos 反射性防护 simple
    file cycle
    Scala
    Hadoop
    数据库
  • 原文地址:https://www.cnblogs.com/qionglouyuyu/p/4199709.html
Copyright © 2011-2022 走看看