【PAT甲级 进位相加】1058 A+B in Hogwarts (20 分) C 全部AC

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/sinat_42483341/article/details/100555422

题目

进位相加
在这里插入图片描述

题解 C

#include<stdio.h>
int main() {
	int a1, b1, c1;
	int a2, b2, c2;
	int a3, b3, c3;
	scanf("%d.%d.%d %d.%d.%d", &a1, &b1, &c1, &a2, &b2, &c2);

	//c位
	c3 = c1 + c2;
	int flagB = c3 / 29;
	c3 %= 29;

	//b位
	b3 = b1 + b2 + flagB;
	int flagA = b3 / 17;
	b3 %= 17;

	//a位
	a3 = a1 + a2 + flagA;

	printf("%d.%d.%d", a3, b3, c3);
}

猜你喜欢

转载自blog.csdn.net/sinat_42483341/article/details/100555422