-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcel_sheet_column_number.cpp
More file actions
42 lines (40 loc) · 1023 Bytes
/
excel_sheet_column_number.cpp
File metadata and controls
42 lines (40 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* =====================================================================================
*
* Filename: excel_sheet_column_number.cpp
*
* Description: 171. Excel Sheet Column Number
* https://leetcode.com/problems/excel-sheet-column-number/
*
* Version: 1.0
* Created: 02/22/2022 11:47:00
* Revision: none
* Compiler: gcc
*
* Author: xianfeng.zhu@gmail.com
* Organization:
*
* =====================================================================================
*/
#include <cstdio>
#include <string>
class Solution {
public:
int titleToNumber(const std::string& title) {
int num = 0;
for (const char c : title) {
num = num * 26 + (c - 'A' + 1);
}
return num;
}
};
int main(int argc, char* argv[]) {
std::string title = "AA";
if (argc > 1) {
title = argv[1];
}
const int num = Solution().titleToNumber(title);
printf("columnTitle = %s\n", title.c_str());
printf("%d\n", num);
return 0;
}