博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2562 Primary Arithmetic
阅读量:4344 次
发布时间:2019-06-07

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

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10724   Accepted: 3980

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. 大坑 CODE:
#include 
#include
#include
#define REP(i, s, n) for(int i = s; i <= n; i ++)#define REP_(i, s, n) for(int i = n; i >= s; i --)#define MAX_N 10 + 5using namespace std;char a[MAX_N], b[MAX_N];int int_a[MAX_N], int_b[MAX_N], la, lb;int main(){ while(scanf("%s%s", a + 1, b + 1) != EOF){ if(a[1] == '0' && b[1] == '0') break; memset(int_a, 0, sizeof(int_a)); memset(int_b, 0, sizeof(int_b)); la = strlen(a + 1), lb = strlen(b + 1); REP(i, 1, la) int_a[la - i + 1] = a[i] - '0'; REP(i, 1, lb) int_b[lb - i + 1] = b[i] - '0'; int i = 1, x = 0, res = 0; while(i <= la || i <= lb){ x = int_a[i] + int_b[i] + x; x /= 10; if(x != 0) res ++; i ++; } if(res == 0) printf("No carry operation.\n"); else if(res == 1) printf("%d carry operation.\n", res); else printf("%d carry operations.\n", res); } return 0;}

 

 

转载于:https://www.cnblogs.com/ALXPCUN/p/4543169.html

你可能感兴趣的文章
JAVA国际化
查看>>
[洛谷P1850]换教室 概率与期望
查看>>
【读书笔记】算法神探
查看>>
8 种百度云高速下载,你值得拥有
查看>>
python爬虫之初始Selenium
查看>>
建造者模式(Builder)
查看>>
javascript实现的可改变滚动方向的无缝滚动
查看>>
职场人伤害了“上司” 怎样弥补
查看>>
int[]数组指定位置添加元素
查看>>
(转)关于ColumnCount与GetItemsCount方法
查看>>
Centos 配置eth0 提示Device does not seem to be present
查看>>
谷歌扩展程序--------------Message
查看>>
IOS_协议与委托
查看>>
男人保持活力25条
查看>>
IOS后台运行浅析
查看>>
更换临时表空间TEMP
查看>>
ios html5 长按复制文本
查看>>
一个真实的社会
查看>>
TreeView控件
查看>>
提示 ToolTip
查看>>