[Blue Bridge Cup 2017 preliminary round] Excel Address

 Title Description

Excel cell address indicates very interesting, it uses letters to represent the column number.
For example, A represents the first column 1, B represents 2, Z represents 26, AA represents 27, AB represents 28, BA represents 53, ....
Of course, Excel is the maximum column number limit, so it is not difficult to convert.
If we want this represents a generalized method, you can put a big number is converted to a long sequence of letters it?
The title both requirements of the digital input, and outputs the corresponding address representation Excel.

Entry

A plurality of sets of test data input, for each set of test data input line containing an integer
integers in the range [1,2147483647] entered.

Export

For each set of test data: output line indicates the answer

Sample input Copy

26
2054

Sample output Copy

FROM
BZZ

Solution: is to convert a decimal to 26 decimal, hexadecimal difference is that 26 this number is not 26, but there is, so to 26 the number of special treatment:

 In the binary number 26, the 26 is represented by two digits, where only a few 'Z' can be expressed, so the number after the subtraction modulo n divides a line

 

#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<map>
#include<stack>
#define ll long long
using namespace  std;
int main()
{
    ll n;
    while(cin>>n)
    {
        stack<char>p;
        while(n)
        {
            IF (n-% 26 == 0 ) // because there is no 26 26 hex this number, but there are the address, so use this form of deposit into 
            {
                p.push('Z');
                n=n/26;
                n- -; // after deposit into, a number to be reduced (for example to 26, 26 two-digit hexadecimal number is represented by 26, but here only to be represented by a number) 
            }
             the else
            {
                p.push((char)('A'+n%26-1));
                n=n/26;
            }
        }
        while(!p.empty())
        {
            cout<<p.top();
            p.pop();
        }
        cout<<endl;
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/-citywall123/p/12339999.html