1058. A + B in Hogwarts (20)-pat

Source: Internet
Author: User
1058. A + B in Hogwarts (20) Time Limit 50 ms memory limit 32000 kb code length limit 16000 B discriminant program standard author Chen, Yue

If you are a fan of Harry Potter, you wocould know the world of magic has its own currency system -- As Hagrid explained it to Harry, "Seventeen silver sickles to a galleon and twenty-nine knuts to a sickle, it's easy enough. "Your job is to write a program
Compute a + B where A and B are given in the standard form of "galleon. Sickle. Knut" (Galleon is an integer in [0, 107], sickle is an integer in [0, 17), and Knut is an integer in [0, 29 )).

Input specification:

Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.

Output specification:

For each test case you shoshould output the sum of A and B in one line, with the same format as the input.

Sample input:

3.2.1 10.16.27

Sample output:

Recommendation index :※
Source: http://pat.zju.edu.cn/contests/pat-a-practise/1058
Don't think too complicated
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int main(){long a[3];long b[3];scanf("%ld.%ld.%ld",&a[0],&a[1],&a[2]);scanf("%ld.%ld.%ld",&b[0],&b[1],&b[2]);int tmp;tmp=a[2]+b[2];if(tmp>=29){a[2]=tmp-29;a[1]++;}elsea[2]=tmp;tmp=a[1]+b[1];if(tmp>=17){a[1]=tmp-17;a[0]++;}elsea[1]=tmp;a[0]+=b[0];int i=0;cout<<a[0]<<"."<<a[1]<<"."<<a[2]<<endl;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.