专栏名称: 来老铁干了这碗代码
目录
相关文章推荐
东方财富网  ·  算力硬件狂潮!“铜光共进”或成新趋势 ·  昨天  
东方财富网  ·  算力硬件狂潮!“铜光共进”或成新趋势 ·  昨天  
广西台新闻910  ·  “伪装”学生就能抢上回家票?最新回应! ·  昨天  
广西台新闻910  ·  “伪装”学生就能抢上回家票?最新回应! ·  昨天  
科技头版  ·  华为分红,人均几十万 ·  2 天前  
科技头版  ·  华为分红,人均几十万 ·  2 天前  
FM1007福建交通广播  ·  NBA | 亚历山大缺席,独行侠终结雷霆4连胜 ·  4 天前  
FM1007福建交通广播  ·  NBA | 亚历山大缺席,独行侠终结雷霆4连胜 ·  4 天前  
51好读  ›  专栏  ›  来老铁干了这碗代码

1058 A+B in Hogwarts (20 分)_7行代码AC

来老铁干了这碗代码  · CSDN  ·  · 2021-02-25 16:17

正文

PAT甲级最优题解——> 传送门


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,10​7​​], 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 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


#include<stdio.h>
int main( ) {
	int a, b, c, e, f, g; 
	scanf("%d.%d.%d %d.%d.%d", &a, &b, &c, &e, &f, &g);
	printf("%d.%d.%d", (a+e)+(b+f+(c+g)/29)/17, (b+f+(c+g)/29)%17, (c+g)%29);
	return 0;
} 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7