Excel Sheet Column Number

Source: Internet
Author: User

This problem can be seen as a 26-in-one question. 26 binary means you can combine up to 26 different symbols to represent a numeric value.

Therefore, the value of the ABC Representative is: a*262+b*261+c*260=1*262+2*261+3*260, other letter combinations and so on.

The following method is a very intuitive idea, but to invoke the C + + library function pow (x,a), the calculation time will be longer.

The POW (x,a) can calculate the a power of X, and the ASCII code of ' a ' is 64.

classSolution { Public:    intTitletonumber (strings) {intN=s.size ()-1; intresult=0;  for(intI=0; i<=n;i++) {result+ = (s[i]- -) *pow ( -, N-i); }        returnresult; }};

A better notation is:

classSolution { Public:    intTitletonumber (strings) {intresult=0;  for(intI=0; I<s.size (); i++) Result=result* -+s[i]-'A'+1; returnresult; }};

Excel Sheet Column Number

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.