Excel Sheet Column Title

Source: Internet
Author: User

It took a long time to finally solve the problem, recording the idea of solving the problem:
Select 26 to solve this problem, the 26 characters {0,a,b,...,y} represent the Arabic numerals {0,1,2,...,25} respectively.

If according to our practice, 26 should be a0,52 for B0 and so on.
Don't be impatient, when we get such a result, we start to convert, taking A0 as an example:
A0 = 1x26^1 +0x26^0
= 0x26^1 +26x26^0
=z;
Similarly for B0:
B0 = 2x26^1 +0x26^0
= 1x26^1 +26x26^0
=az;
That is, the high 1 represents the low 26, the high position minus 1, the low plus 26, in this way we realized the conversion.
Here's the code:

Class Solution { Public:string Converttotitle(intN) {stringarr[ -] = {"0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y"};stringResintQuotient,remainder; quotient = n; for(; Quotient! =0; ) {remainder = quotient% -; quotient = quotient/ -;if(Remainder = =0) {res ="Z"+ res; quotient = quotient-1; }Elseres = Arr[remainder] + res; }returnRes }};

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Excel Sheet Column Title

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.