Hdu2100lovekey (High precision 26-in)

Source: Internet
Author: User

Lovekey Time limit:3000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5104 Accepted Submission (s): 1661


Problem Description XYZ-26 binary number is a number that is a capital letter per digit. A, B, C 、...、 X, Y, Z, respectively, represent a number 0 ~ 25, and an n-bit 26 binary number is converted into a 10-binary rule as follows
A0a1a2a3 ... The number of each digit represented by the An-1 is a0a1a2a3...an-1, then the 10 binary value of the XYZ-26 number is

m = a0 * 26^ (N-1) + A1 * 26^ (N-2) + ... + an-3* 26^2 + an-2*26 + an-1

One day Vivi suddenly played a romantic, to hide in the school of a classroom, let maple ice leaves to find, of course, she also know maple ice leaves is not road fetish, so found XYZ small shrimp and water prodigal help, they will in the door of the classroom of the XYZ-26, respectively write a number of a and B, respectively, And a password is set on the door lock. Obviously, only the password can be found to open the lock, smoothly into the classroom. This set of passwords is called Lovekey by the members of XYZ. Fortunately, Maple ice leaves know that Lovekey is a 10 binary value with B's 10 binary value and the XYZ-26 binary form. Of course, the shrimp and water prodigal son do not want to difficult maple ice leaves, so a and B are not more than 200 digits.
For example, the first set of test data
A = 0 * 26^5+0* 26^4+ 0* 26^3+ 0 *26^2 + 3*26 + 7 = 85
b = 1*26^2 + 2*26 + 4 = 732
Then A + b = 817 = BFL
The Input topic has multiple sets of test data.
Each set of test data contains a XYZ-26 number of two values, each of which contains only uppercase letters and no more than 200 bits per digit.
Output Lovekey of XYZ, one row per set of outputs.
Sample Input

Aaaadh BCE DRW UHD D AAAAA
Sample Output
BFL XYZ D
26 binary, then convert to 10 binary


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int MAXN = +;
int NUM1[MAXN],NUM2[MAXN],SUM[MAXN];
string str1,str2;

void Solve () {
    memset (num1,0,sizeof (NUM1));
    memset (num2,0,sizeof (num2));
    memset (sum,0,sizeof (sum));
    int len1 = Str1.size ();
    int len2 = Str2.size ();
    for (int i=len1-1,k=0; i>=0; i--) num1[k++]=str1[i]-' A ';
    for (int i=len2-1,k=0; i>=0; i--) num2[k++]=str2[i]-' A ';
    int maxlen = max (len1,len2);
    for (int i=0; i<maxlen; i++) {
        sum[i]+= (num1[i]+num2[i]);
        if (sum[i]>=26) {sum[i+1]++; sum[i]%=26;}
    }
    int i=maxn-1;
    while (sum[i]==0 && i>=0) i--;
    if (i==-1) cout<< ' A ';
    else while (i!=-1) Cout<<char (sum[i--]+ ' A ');
    cout<<endl;
}
int main ()
{
    while (CIN>>STR1>>STR2) solve ();
    return 0;
}




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.