HDU-2100-lovekey

Source: Internet
Author: User

Question Link

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2100

At the beginning of this question, I have been thinking about converting the 26th to the 10th, and converting the 26th to the 26th, and the 200 characters won't work,

I am stuck and won't do it. Later I learned that it is a 200-length string, so I used the idea of adding large numbers.

Reference the idea of http://blog.csdn.net/stm32f98233/article/details/4427447

Solution: it is also a problem of hexadecimal conversion. In fact, it is an inverse process to convert a letter into a 10-digit system and then convert it back to a 26-digit system. There is no need to convert it into a 10-digit system. Just add the 26-digit system. If the sum of the sum is greater than 25, carry the number. Don't be fooled by the question prompts. Because it is a string of 200 characters in length, it is the thought of adding large numbers.

Note: if the data is aaaaaaaaa *, the final result is * and * is any letter. This is a special case.

 

 

Sort the strings in reverse order. For ease of calculation, add zero to the strings with less length, and output them in reverse order.

 

My AC code

# Include <stdio. h>
# Include <string. h>
Char A [210], B [210], C [210], d [210];
Int main (void)
{
Int I, p, q, N, S;
While (scanf ("% S % s", c, d) = 2)
{
P = strlen (C );
Q = strlen (d );
For (I = p-1; I> = 0; I --)
A [p-1-i] = C [I];
A [p] = '\ 0 ';
For (I = q-1; I> = 0; I --)
B [q-1-i] = d [I];
B [Q] = '\ 0 ';
N = P;
If (P <q)
{
For (I = P; I <q; I ++)
A [I] = 'a ';
A [I] = '\ 0 ';
N = Q;
}
If (P> q)
{
For (I = Q; I <p; I ++)
B [I] = 'a ';
A [I] = '\ 0 ';
N = P;
}
S = 0;
For (I = 0; I <n; I ++)
{
A [I] = A [I] + B [I] + S-'A ';
If (A [I]> 'Z ')
{
S = 1;
A [I] = A [I]-26;
}
Else
S = 0;
}
If (S = 1)
{
A [I] = 'B ';
N ++;
}
For (I = n-1; I> = 0; I --)
{
If (A [I] = 'A ')
N --;
Else
Break;
}
For (I = n-1; I> = 0; I --)
Printf ("% C", a [I]);
Printf ("\ n ");
}
Return 0;
}

 

I think more about the questions to make progress.

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.