zoukankan      html  css  js  c++  java
  • LeetCode 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

     1 /*************************************************************************
     2     > File Name: LeetCode171.c
     3     > Author: Juntaran
     4     > Mail: Jacinthmail@gmail.com
     5     > Created Time: 2016年05月10日 星期二 04时02分20秒
     6  ************************************************************************/
     7 
     8 /*************************************************************************
     9 
    10     Excel Sheet Column Number
    11 
    12     Related to question Excel Sheet Column Title
    13 
    14     Given a column title as appear in an Excel sheet, 
    15     return its corresponding column number.
    16 
    17     For example:
    18 
    19         A -> 1
    20         B -> 2
    21         C -> 3
    22         ...
    23         Z -> 26
    24         AA -> 27
    25         AB -> 28
    26 
    27  ************************************************************************/
    28 
    29 #include "stdio.h"
    30 
    31 int titleToNumber(char* s)
    32 {
    33     int sum = 0;
    34     int i;
    35     for( i=0; i<strlen(s); i++ )
    36     {
    37         sum = 26*sum + (s[i]-'A'+1);
    38     }
    39     printf("%d
    ",sum);
    40     return sum;
    41 }
    42 
    43 int main()
    44 {
    45     char* s = "AB";
    46     titleToNumber(s);
    47     return 0;
    48 }
  • 相关阅读:
    Qt禁止调整窗口的大小
    CentOS 6.2修改主机名
    怎么培养新人
    软件的质量控制
    如何留住骨干
    物化视图索引引发的问题
    Oracle查询脚本优化
    Oracle视图编译错误解决办法
    spring切面配置,代理用jdk和cglib的区别
    Tomcat起了一个测试桩,调用该测试桩无响应
  • 原文地址:https://www.cnblogs.com/Juntaran/p/5479093.html
Copyright © 2011-2022 走看看