Excel Sheet Column Title total accepted:18284 total submissions:103291 My submissions Question SolutionGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example:Test instructions is very clear.The code is as follows:class Solution {public: stringconvertToTitle(int n) { string t; while(n>0) {
Leetcode: Excel Sheet Column Number
I. Question
Returns the column number corresponding to a column title that appears in an Excel table.
For example:
A-> 1
B-> 2
C-> 3
...
Z-> 26
AA-> 27
AB-> 28
Ii. Analysis
The question is very clear. In fact, a careful analysis is very simple, that is, converting a string into a deformation of the integer (atoi ()-
; Break; Case 'W': Ans= at; Break; Case 'X': Ans= -; Break; Case 'Y': Ans= -; Break; Case 'Z': Ans= -; Break; default: Break; } returnans; }};After looking at other people's code, deeply feel their weak. They use ASCII code to greatly reduce the cumbersome switch case.int titletonumber (string s) { int len = s.length (), sum=0; for (int i=0; i) + =(int(s[i]-'A'+1)) *pow(+, len-1- i); return sum;}Just a few lines of code will solve the problem,
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z Idea: First look at the law:1--26 (A--z)26+1--26+26 (Aa--az)26+26+1--26+26+26 (BA--BZ)Set a given number of N, we have to find a way to first to find out the last remaining position, because the remainder is 1--26 (a--z),And the result of the remainder operation will appear 0, so we pass (n-1)% 26来 cal
Topic:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z Solution:public class Solution {public String converttotitle (int n) { //char a[26]={' A ', ' B} String s = ""; String res = ""; while (n > 0) { n--; s = n%26 + S; res = (char) (n%26+ ' A ') + res; n = n/26; }
The number of a column in an Excel table, a A-Z combination, represents a specific number.Example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
Solving:
ABC =A? 2 +B? 1 +C ? 0
So the code is implemented as:
class Solution {
public:
int titleToNumber(string s) {
int res = 0,pow=1;
for (size_t i = 0; i s.size(); i++)
{
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z 1 Public classSolution {2 PublicString Converttotitle (intN) {3 if(N 0)return "";4 5StringBuilder SB =NewStringBuilder ();6 7 while(N >=1){8 CharCH = (Char) ((N-1) % -+'A');9n = (n-1) / -;Ten sb.append (CH); One } A - sb.reverse (); - retur
Test instructions: converting a number to an item in a row in an Excel tableThe essence is 10 binary conversion to 26, but in the middle to add a different operation, before each operation requires n--1 classSolution {2 Public:3 stringConverttotitle (intN) {4 stringS"");5 for(; n--; n/= -){6s + =string("A");7S[s.size ()-1] + = n% -; 8 }9 Reverse (S.begin (), S.end ());Ten returns; One } A}Leetcode 168
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z Credits:Special thanks to @ifanchu for adding this problem and creating all test cases.Class Solution {public: string converttotitle (int n) { string res= ""; if (n==0) return res; while (n>0) { int t = n%26; if (t==0) {
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z 1 Public classSolution {2 PublicString Converttotitle (intN) {3String result= "";4 while(n!=0){5String a= "";6 intTemp=n%26;7 if(temp==0){8A=string.valueof (' Z ');9N=n-26;Ten } One Else{ AA=string.valueof ((Char) (temp-1+ ' A ')); -
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z Basic ideas:In essence, an integer is converted from 10 to 26 binary.Since ' A ' corresponds to 1, not 0, it needs to be adjusted, i.e. minus 1 operations.Class Solution {public: string converttotitle (int n) { stackInsert directly in front of the string, you can omit the stack:Class Solution
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AB, AA, Z 1 classSolution {2 Public:3 stringConverttotitle (intN) {4 strings;5 CharC=0;6 while(n) {7 if(n% -) {8c ='A'+ n% --1;9 S.insert (S.begin (), c);Ten } One Else { AC='Z'; -N-= -; - S.insert (S.begin (), c); the } -N/= -; -
Copy codeThe Code is as follows:-- Get table (worksheet) or column (field) listings from an excel spreadsheet-- Set variablesDeclare @ linkedServerName sysname = 'tempexcelspreadsheet'Declare @ excelFileUrl nvarchar (1000) = 'd: \ text.xlsx'--/SET-- Delete the Link Service (if it already exists)If exists (select null from sys. servers where name = @ linkedServerName) beginExec sp_dropserver @ server = @ linkedServerName, @ droplogins = 'droplogins'End
When I use C # to tune the Excel file, I am not prompted to delete sheet2008-12-17. Author: Source: browse: 567 comments: publish comments to ask experts
Recommended:Start Network-Professional server/server sharing service provider 17hz.net-5 years server sharing service
When you use C # To adjust the worksheet. Delete of an Excel object to delete the sheet i
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1, A 2, B 3, C ... AA, Z Credits:Special thanks to @ifanchu for adding this problem and creating all test cases.It is essentially a 10-to-26 conversion, but the mapping of the 1~26 is not good, so the map minus 1 becomes 0~25 better.1 classSolution {2 Public:3 stringConverttotitle (intN) {4 strings;5 intid
(Microsoft ActiveX Data Objects 2.X Library)
' Link all sheet to a total table
' The first row of the table to be merged must be a field name, not a merged cell
Sub Sql_ado_excel_join_all ()
Dim CNN as New ADODB. Connection
Dim rs as New ADODB. Recordset
Dim I, K, shcount as Integer
Dim SQL, SQL2 As String, cnnstr as String
Dim S1, S2, S3, TMP as String
Dim ws as Worksheet
Const Ididx = 1
Const Scoreidx = 3
Shcount = ActiveWorkbook.Sheets.Count
' Get
When you need to enter massive amounts of data in an Excel worksheet, typically, the input is done column by row, but this method of inputting data wastes a lot of valuable time in switching rows and columns, and it's easy to make mistakes, and you can use the "record sheet" feature provided by Excel to quickly enter data.
Operation Steps:
1, in the Open
#region Get the Sheet page (worksheet) name collection in the Excel workbook/// Copyright notice: Author: jiankunking Resources: http://blog.csdn.net/jiankunking The author and csdn partner, welcome reprint. However, if the submit permission is not declared from this section, it must be persisted and connected to the original article page given the view location. C # Get the name of the
Leetcode 154: 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
Credits:Special thanks to @ ifanchu for adding this problem and creating all test cases.
Public class Solution {public
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.