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 456
555 555
123 594
0 0
Sample Output
No carry operation.
3 carry operations.
1 carry operation.
#define RUN
#ifdef RUN
#include <stdio.h>
int main() {
#ifndef ONLINE_JUDGE
freopen("10035.in", "r", stdin);
freopen("10035.out", "w", stdout);
#endif
int a, b;
while (scanf("%d%d",&a,&b) == 2){
if (!a && !b) return 0;
int c = 0, ans = 0;
for (int i = 9; i >= 0; i--) {
c = (a%10 + b%10 + c) > 9 ? 1 : 0;
ans += c;
a /= 10; b /= 10;
}
//printf("%d\n", ans);
if(ans == 0){
printf("No carry operation.\n");
}
else if(ans == 1){
printf("%d carry operation.\n", ans);
}
else{
printf("%d carry operations.\n", ans);
}
}
return 0;
}
#endif
分享到:
相关推荐
Floating-point arithmetic is considered an esoteric subject by many people. This is rather surprising because floating-point is ubiquitous in computer systems. Almost every language has a floating-...
ieee-754 2019最新标准。奉献给大家!754-2019 - IEEE Standard for Floating-Point Arithmetic, ieee 浮点标准,2019年
Fixed-Point Arithmetic: An Introduction Randy Yates
IEEE754 IEEE standard for binary floating-point arithmetic英文版 IEEE754二进制浮点数算术运算标准.pdf IEEE标准
计算机课程资源 简单众数问题The number problem algorithm
Title:Evaluation of IEEE 754 Floating -Point Arithmetic Compliance Across a Wide Range of Heterogeneous Computers Introduction:Scientific applications rely heavily on floating-point arithmetic[1] ...
This standard specifies interchange and arithmetic formats and methods for binary and decimal floating-point arithmetic in computer programming environments. This standard specifies exception ...
二进制浮点运算标准英文版 PDF格式,内容是英文的。。。
This standard specifies interchange and arithmetic formats and methods for binary and decimal floating-point arithmetic in computer programming environments. This standard specifies exception ...
IEEE Standard 754 for Binary Floating-Point Arithmetic ,英文原版IEEE745标志,二进制浮点数算法
Solomon I. Khmelnik - Computer Arithmetic of Geometrical Figures-Lulu (2004).pdf
快速算术编码源代码-Fast Arithmetic Coding(Amir Said) Amir Said的快速算术编码的C++实现,包含源代码、测试文件,使用说明等
ISO IEC 60559:2020(IEEE Std 754) Floating-point arithmetic - 完整英文电子版(84页).pdf
定点数据的存储方式,基本的算术运算处理方式,C语言实现
IEEE Standard for Floating-Point Arithmetic (IEEE Std 754™-2019)
开源项目-moxar-arithmetic.zip,arithmetic parsing lib in go, using reverse-polish notation
用c++编写程序计算两个数相加的进位次数
通过解决问题,了解如何在 Matlab 中进行基本算术和运算顺序。 我们将介绍如何在计算中进行加、减、乘、除,以及如何使用括号、指数等进行计算。
npm install babel-plugin-precise-arithmetic --save-dev 添加babel-plugin-精确算法 .babelrc { " plugins " : [ " precise-arithmetic " ] } 或者 webpack.config.js ... { test : / \. js $ / , loader : ...