HDU 1720 A + B coming

Source: Internet
Author: User

A + B coming
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5856 accepted submission (s): 3839


Problem descriptionattributes classmates said to me that a + B is must needs.
If you can't ac this problem, you wocould invite me for night meal. ^_^
 
Inputinput may contain multiple test cases. Each case contains A and B in one line.
A, B are hexadecimal number.
Input terminates by EOF.
 
Outputoutput A + B in decimal number in one line.
Sample Input
1 9A Ba b
 
Sample output
102121
 
Author whisky
Sourcehziee 2007 programming contest




Solution: A water question is a hexadecimal A + B. You only need to output the calculated result in decimal format. However, it is quite disgusting to have wa several times...





AC code:

#include <iostream>#include <string>#include <cstdio>#include <cmath>using namespace std;int main(){//freopen("in.txt", "r",stdin);string a, b;int x, y;while(cin>>a>>b){int len = a.size();int cnt1 = 0;int k = 0;while(len){char x = a[len-1];if(x>='0' && x<='9')  cnt1 += (x - '0')*pow(16, k);else if(x>='a' && x<='f')  cnt1 += (x - 'a' + 10)*pow(16, k);else  cnt1 += (x - 'A' + 10)*pow(16, k);len --;k ++;}len = b.size();int cnt2 = 0;k = 0;while(len){char x = b[len-1];if(x>='0' && x<='9')  cnt2 += (x - '0')*pow(16, k);else if(x>='a' && x<='f')  cnt2 += (x - 'a' + 10)*pow(16, k);else  cnt2 += (x - 'A' + 10)*pow(16, k);len --;k ++;}cout<<(cnt1 + cnt2)<<endl;}return 0;}






HDU 1720 A + B coming

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.