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 }
  • 相关阅读:
    CentOS离线状态下安装Python3.7.0
    SQL练习题
    ajax的工作原理
    总结 XSS 与 CSRF 两种跨站攻击
    转css中文英文换行、禁止换行、显示省略号
    vue项目的搭建
    转axios 的应用
    rem布局计算(移动端,pc端有兼容性)
    rem
    彻底弄懂css中单位px和em,rem的区别
  • 原文地址:https://www.cnblogs.com/Juntaran/p/5479093.html
Copyright © 2011-2022 走看看