#13381: C


hcyang (中輟生)

學校 : 國立交通大學
編號 : 73167
來源 : [36.226.225.170]
最後登入時間 :
2019-07-14 15:48:53
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [36.224.44.94] | 發表日期 : 2018-02-10 12:50

#include <stdio.h>
#include <stdlib.h>
int main() {
int a,b;
while(scanf("%d %d",&a,&b)==2&&(a!=0||b!=0))
{
int c=a+b;
int count=0;int temp4=0;
while(1)
{
int temp=a%10;
int temp2=b%10;
if(temp>temp2)
temp2+=temp4;
else
temp+=temp4;
int temp3=c%10;
if(temp3<=temp2&&temp3<=temp&&temp!=0&&temp2!=0)
{
count++;
temp4=1;
}
else
temp4=0;
a/=10;
b/=10;
c/=10;
if(a==0&&b==0&&c==0)
{
break;
}
}
if(count==1)
printf("1 carry operation.\n");
if(count==0)
printf("No carry operation.\n");
if(count>1)
printf("%d carry operations.\n",count);
}
return 0;
}

 
#16656: Re:C


freedom501999@gmail.com (帥氣魔方生)

學校 : 不指定學校
編號 : 88611
來源 : [39.8.203.54]
最後登入時間 :
2019-05-30 22:56:25
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [39.12.107.19] | 發表日期 : 2019-01-26 12:52

 



#include <stdio.h>
int main(void)
{
	long long int a, b;
	int c, carry, car;
	while(scanf("%lld %lld", &a, &b)&&(a|b))
	{
		carry=car=0;
		while(a>0 || b>0)
		{
			c= a%10 + b%10 + car;
			if(c>=10)
			{
				carry++;
				car=1;
			}
			else
				car=0;
			a/=10;
			b/=10;
		}
		if(carry==0)
			printf("No carry operation.\n");
		else if(carry==1)
			printf("1 carry operation.\n");
		else
			printf("%d carry operations.\n",carry);
	}
	return 0;
}
 
ZeroJudge Forum