博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2562
阅读量:6267 次
发布时间:2019-06-22

本文共 1830 字,大约阅读时间需要 6 分钟。

Primary Arithmetic

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7852 Accepted: 2962

Description

Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.

Input

Each line of input contains two unsigned integers less than 10 digits. The last line of input contains 0 0.

Output

For each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers, in the format shown below.

Sample Input

123 456555 555123 5940 0

Sample Output

No carry operation.3 carry operations.1 carry operation.

Source

 
模拟加法进位
#include 
#include
using namespace std;int num1[15], num2[15];char ch[15],ch1[15];int num1_len, num2_len, max_len;int sum;int main(){ while(scanf("%s%s",ch,ch1)!=EOF) { if(!strcmp(ch,"0") && !strcmp(ch1,"0")) break; sum=0; memset(num1,0,sizeof(num1)); memset(num2,0,sizeof(num2)); num1_len=strlen(ch); num2_len=strlen(ch1); for(int i=0; i
num2_len?num1_len:num2_len; for(int i=0; i
=10) { num1[i+1]+=(num1[i]+num2[i])/10; sum++; } } if(sum==1) printf("%d carry operation.\n",sum); else if(sum>1) printf("%d carry operations.\n",sum); else printf("No carry operation.\n"); } return 0;}

转载于:https://www.cnblogs.com/eric-blog/archive/2011/06/02/2068737.html

你可能感兴趣的文章
PHP写文件函数
查看>>
mysql的sql_mode合理设置
查看>>
函数连续性与可导性
查看>>
linux下libevent安装
查看>>
用ip来获得用户所在地区信息
查看>>
卡尔曼滤波
查看>>
linux下面覆盖文件,如何实现直接覆盖,不提示
查看>>
CSS3阴影 box-shadow的使用和技巧总结
查看>>
Linux下高cpu解决方案
查看>>
SQL事务用法begin tran,commit tran和rollback tran的用法
查看>>
centos7 crontab笔记
查看>>
.Net AppDomain.CurrentDomain.AppendPrivatePath(@"Libs");
查看>>
【Unity3D基础教程】给初学者看的Unity教程(零):如何学习Unity3D
查看>>
Android Mina框架的学习笔记
查看>>
合并两个排序的链表
查看>>
rtf格式的一些说明,转载的
查看>>
REST Security with JWT using Java and Spring Security
查看>>
echarts学习总结(二):一个页面存在多个echarts图形,图形自适应窗口大小
查看>>
IIS7显示ASP的详细错误信息到浏览器
查看>>
使用fiddler对手机APP进行抓包
查看>>