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: [email protected]
 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 }
时间: 2024-08-01 23:15:53

LeetCode 171的相关文章

Leetcode 171 Excel Sheet Column Number 难度:0

https://leetcode.com/problems/excel-sheet-column-number/ class Solution { public: int titleToNumber(string s) { int ans = 0; for(int i = 0;i < s.length();i++) { ans *= 26; ans += s[i] - 'A' + 1; } return ans; } };

Leetcode 171 Excel Sheet Column Number 字符串处理

本质是把26进制转化为10进制 A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 1 class Solution { 2 public: 3 int titleToNumber(string s) { 4 int ans = 0; 5 for(int i = 0; i<s.size(); ++i){ 6 ans = 26 * ans + s[i] - 'A' + 1; 7 } 8 return ans; 9 }

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 class Solution { public: int titleToNu

leetcode——171 Excel Sheet Column Number (表格字母与整数的映射)

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 Hide Tags: M

leetcode:171 Excel Sheet Column Number-每日编程第十题

Excel Sheet Column Number Total Accepted: 54683 Total Submissions: 140674 Difficulty: Easy 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 -

LeetCode: 171 Excel Sheet Column Number(easy)

题目: 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 class Solution { 2 public: 3

LeetCode 171 JAVA

public class Solution { private static Scanner sc = null; private static final int RADIX = 26; enum Alphabet { A(1), B(2), C(3), D(4), E(5), F(6), G(7), H(8), I(9), J(10), K(11), L(12), M(13), N(14), O(15), P(16), Q(17), R(18), S(19), T(20), U(21), V

LeetCode 171周赛题解

1317. 将整数转换为两个无零整数的和 1 class Solution { 2 public: 3 bool check(int n){ 4 while(n){ 5 if(n%10==0){ 6 return false; 7 } 8 n=n/10; 9 } 10 return true; 11 } 12 vector<int> getNoZeroIntegers(int n) { 13 for(int i=1;i<=n;i++){ 14 if(check(i)&&c

nomasp 博客导读:Android、UWP、Algorithm、Lisp(找工作中……

Profile Introduction to Blog 您能看到这篇博客导读是我的荣幸.本博客会持续更新.感谢您的支持.欢迎您的关注与留言.博客有多个专栏,各自是关于 Android应用开发 .Windows App开发 . UWP(通用Windows平台)开发 . SICP习题解 和 Scheme语言学习 . 算法解析 与 LeetCode等题解 .而近期会加入的文章将主要是算法和Android.只是其他内容也会继续完好. About the Author 独立 Windows App 和