ACM Serial Number Interchange

Source: Internet
Author: User

Serial Number Interchange time limit:MS | Memory limit:65535 KB Difficulty:2
Describe

Dr.kong designed a smart robot, which will quickly calculate cell coordinates in a spreadsheet. The row coordinates of a cell are numeric ordinal numbers numbered by numbers, and column coordinates use alphabetic numbers. Looking at the alphabetical sequence, we found that the alphabetical sequence number 1th through 26th was a,b,...,z, followed by the 27th column ordinal of AA, the 28th column AB, and so on.

If you give Dr.kong robot a number (such as 32), it can quickly calculate the equivalent of the letter sequence number (ie, AF), if you give the robot a letter number (such as AA), it can also quickly calculate the equivalent number (27), you can compete with the man, see who can calculate faster and more accurate.

Input
First line: N indicates how many sets of test data are available.
Next there are n rows, each of which is either a positive integer or a string consisting only of uppercase letters.
Input guarantee, all numbers and alphanumeric numbers corresponding to the number are ≤2*10^9
Output
for each row of test data, output one line. If the input is a positive integer ordinal, the output is equivalent to the alpha ordinal, and if the input is a string, the equivalent numeric sequence number is output.
Sample input
327GAA
Sample output
AA727


Using the VS C + + compiler, the compiler calls the C + + POW function directly without invoking the POW function of C. The C + + version of the POW does not have an int parameter, can only be converted to a double type, and the compiler on the site seems to be using the gcc,double to int data type conversion will prompt an error, tangled for half an hour ....
#include <stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>intChartonum (Char*str) {    intnum =0; intLen =strlen (str); inti =0;  while(I <Len) {num+ = (Str[i]-'A'+1) * POW ( -, (Len-i-1)); I++; }    returnnum;}voidNumtochar (intNumChar*str) {    inti =0;  while(Num >0)    {        Charc ='A'+ num% --1; intA = num/= -; if(c = ='A'-1) {Str[i]='Z'; Num= A-1; }        Else{Str[i]=C; Num=A; } I++; } Str[i]=' /'; Num= I1; I=0;  while(Num >i) {Chartemp =Str[num]; Str[num]=Str[i]; Str[i]=temp; Num--; I++; }}intMain () {intnum =0; scanf ("%d", &num);  while(num--)    {        Chartest[Ten]; scanf ("%s", test); if(test[0] <='9'&& test[0] >'0')        {            intTestnum =atoi (test); Charteststr[Ten];            Numtochar (Testnum, TESTSTR); printf ("%s\n", TESTSTR); }        Elseprintf ("%d\n", Chartonum (test)); }    return 0;}

ACM Serial Number Interchange

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.