1058 A+B in Hogwarts (20 分)混合进制

版权声明:假装这里有个版权声明…… https://blog.csdn.net/CV_Jason/article/details/85239938

题目

If you are a fan of Harry Potter, you would 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 to compute A+B where A and B are given in the standard form of Galleon.Sickle.Knut (Galleon is an integer in [ 0 , 1 0 7 ] [0,10^7] , Sickle is an integer in [ 0 , 17 ) [0, 17) , and Knut is an integer in [ 0 , 29 ) [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 should 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:

14.1.28

解题思路

  题目大意: 实现《哈利波特》里霍格沃茨的货币计算方式,其中加仑可以看做是十进制,西可是17进制,纳特是29进制。实现这种混合进制加法。
  解题思路: 对应单位相加取模,注意进位即可。

/*
** @Brief:No.1058 of PAT advanced level.
** @Author:Jason.Lee
** @Date:2018-12-24
** @Solution: https://blog.csdn.net/CV_Jason/article/details/85239938
*/

#include<iostream>
using namespace std;

int main(){
	int g1,g2,s1,s2,k1,k2;
	scanf("%d.%d.%d %d.%d.%d",&g1,&s1,&k1,&g2,&s2,&k2);
	printf("%d.%d.%d\n",(g1+g2+((k1+k2)/29+s1+s2)/17),((k1+k2)/29+s1+s2)%17,(k1+k2)%29);	
	return 0;
}

在这里插入图片描述

总结

  emmmm……甲级居然有这么水的题???为啥我考试的时候没遇到?1分钟AC,史上最短代码……。

猜你喜欢

转载自blog.csdn.net/CV_Jason/article/details/85239938