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\n",sum);
40     return sum;
41 }
42 
43 int main()
44 {
45     char* s = "AB";
46     titleToNumber(s);
47     return 0;
48 }

 

转载于:https://www.cnblogs.com/Juntaran/p/5479093.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值