[PAT] Grade carry adding 1058 A + B in Hogwarts (20 minutes) C all AC

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/sinat_42483341/article/details/100555422

topic

Carry addition
Here Insert Picture Description

C solution to a problem

#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);
}

Guess you like

Origin blog.csdn.net/sinat_42483341/article/details/100555422