首页 > 其他 > 详细

NYOJ_74 小学生算术

时间:2015-08-16 13:50:28      阅读:215      评论:0      收藏:0      [点我收藏+]

题目地址

分析:

把输入的数字的各个位 分配到一个数组中来计算。

/*
计算两个三位数在相加时需要多少次进位。
你编制的程序应当可以连续处理多组数据。
直到读到两个0(这是输入结束标记)。
*/
#include<iostream>
using namespace std;
void assignment(int num[3],int numn)
{
	num[0]=numn/100;
	num[1]=numn/10%10;
	num[2]=numn%10;
}
int main()
{
	int a[3]={0};
	int b[3]={0};
	int numa,numb;

	while(1)
	{
		cin>>numa>>numb;
		if(numa==0&&numb==0) break;
		
		assignment(a,numa);
		assignment(b,numb);
		
		int temp[3]={0};
		if(a[2]+b[2]>=10) temp[2]=1;
		if(a[1]+b[1]+temp[2]>=10) temp[1]=1;
		if(a[0]+b[0]+temp[1]>=10) temp[0]=1;
		cout<<temp[0]+temp[1]+temp[2]<<endl;
	}
	return 0;	
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

NYOJ_74 小学生算术

原文:http://blog.csdn.net/think_ycx/article/details/47701499

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!