[LeetCode] 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 

实现代码:

/*****************************************************************************
    *  @COPYRIGHT NOTICE
    *  @Copyright (c) 2015, 楚兴
    *  @All rights reserved
    *  @Version  : 1.0

    *  @Author   : 楚兴
    *  @Date     : 2015/2/6 14:29
    *  @Status   : Accepted
    *  @Runtime  : 15 ms
*****************************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
	int titleToNumber(string s) {
		int column = 0;
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] >= 'A' && s[i] <= 'Z')
			{
				column = column * 26 + s[i] - 'A' + 1;
			}
		}
		return column;
	}
};
int main()
{
	Solution s;
	int a = s.titleToNumber("AA");
	cout<<a<<endl;
	system("pause");
}
时间: 2024-08-01 22:49:50

[LeetCode] Excel Sheet Column Number的相关文章

[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 [分析] 可以看成是一道26进制转换为10进制的题目. 跟 [Le

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 C++实现代码: #include<iostream> #inc

[LeetCode] Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 实现代码: /*************************************************************************

[LeetCode]168.Excel Sheet Column Title

[题目] Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB [分析] Because any_pos_int mod 26 should return a number in the interval [0,

Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB   C++实现代码: #include<iostream> #include<string> #include<algorithm

在线等大神-poi导出后台提示报错,Minimum column number is 0!

问题描述 poi导出后台提示报错,Minimum column number is 0! 今天在用poi做导出的时候遇到一些问题! java.lang.IllegalArgumentException: Minimum column number is 0 at org.apache.poi.ss.util.CellRangeAddressBase.validateColumn(CellRangeAddressBase.java:73) at org.apache.poi.ss.util.Cel

C#控制Excel Sheet使其自适应页宽与列宽的方法_C#教程

本文实例讲述了C#控制Excel Sheet使其自适应页宽与列宽的方法.分享给大家供大家参考,具体如下: ///// <summary> /// 1.Clear CircleReference /// 2.Set Page to Fit Wide /// 3.Set Column Text fit /// </summary> /// <param name="app"></param> /// <param name="

c# NOPI CopySheet 这个复制Excel Sheet函数

问题描述 复制同一个文件中的sheet没问题复制其他文件的sheet就出现问题复制过来的是个空表 解决方案 解决方案二:之前用NOPI,上次代码什么的都写完了,最后在保存成2007格式的时候,破函数有bug,文件稍微大点就保存不了,生成的文件打不开,无奈弃用,换成asposecell才解决,比NOPI好用一百倍,CSDN有下载,破解的解决方案三:而且速度,占用内存,兼容方面都要好得多

Select data from an Excel sheet in MSSQL_数据库其它

select *  from openrowset('Microsoft.Jet.OLEDB.4.0' ,'Excel 8.0;HDR=YES;IMEX=1;DATABASE=d:\folder\excel.xls',Sheet1$) -------NOTE------ Setting IMEX=1 tells the driver to use Import mode. In this state, the registry setting ImportMixedTypes=Text will