1. 程式人生 > >1058 A+B in Hogwarts (20 分)混合進位制

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

題目

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,史上最短程式碼……。