UVA OJ 10035 - Primary Arithmetic
Primary Arithmetic
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.
#include <cstdio> using namespace std;
int main()
{
int n, m;
while (scanf("%d%d", &n, &m) == 2)
{
if (n == 0 && m == 0)
break;
int c=0, sum=0;
while (n != 0 || m != 0)
{
c = (n % 10 + m % 10 + c) >= 10 ? 1 : 0;
sum += c;
m = m / 10;
n = n / 10;
}
if (sum == 0)
printf("No carry operation.\n");
else if (sum==1)
printf("%d carry operation.\n", sum);
else
printf("%d carry operations.\n",sum);
}
return 0;
}
本题陷阱就是当进位为0或1时,operation为单数,忽略了为1是也是单数,所以没有一次AC。
UVA OJ 10035 - Primary Arithmetic的更多相关文章
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- POJ 2562:Primary Arithmetic
Primary Arithmetic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11135 Accepted: 40 ...
- 九度OJ 1143:Primary Arithmetic(初等数学) (进位)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:616 解决:254 题目描述: Children are taught to add multi-digit numbers from ri ...
- UVa OJ 458
The Decoder Write a complete program that will correctly decode a set of characters into a valid m ...
- UVA OJ 623 500!
500! In these days you can more and more often happen to see programs which perform some useful cal ...
- uva oj 567 - Risk(Floyd算法)
/* 一张有20个顶点的图上. 依次输入每个点与哪些点直接相连. 并且多次询问两点间,最短需要经过几条路才能从一点到达另一点. bfs 水过 */ #include<iostream> # ...
- 1350. Primary Arithmetic
Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find th ...
- UVa OJ 194 - Triangle (三角形)
Time limit: 30.000 seconds限时30.000秒 Problem问题 A triangle is a basic shape of planar geometry. It con ...
- UVa OJ 175 - Keywords (关键字)
Time limit: 3.000 seconds限时3.000秒 Problem问题 Many researchers are faced with an ever increasing numbe ...
随机推荐
- 攻防世界 reverse crazy
crazy 百越杯2018 查看main函数: int __cdecl main(int argc, const char **argv, const char **envp) { __int64 v ...
- Java 添加数字签名到Excel以及检测、删除签名
Excel中可添加数字签名以供文档所有者申明文档的所有权或有效性.文本以Java代码示例介绍如何在Excel文档中对数字签名功能进行相关操作,包括如何添加签名到Excel.检测Excel文档是否已签名 ...
- ubuntu修改默认启动内核
一.序言 新换的笔记本由于太新的主板芯片,驱动还没有完善.每次升级系统内核都要小心谨慎.经常发生部分硬件驱动失败的事情.系统Ubuntu 20.04.2 LTS x86_64 ,我现在使用的两个版本的 ...
- du和df的统计结果为什么会不一样?
du和df的统计结果为什么会不一样? 今天有个人问我du和df的统计结果为什么会不同,接下来我们分析一下. 我们常常使用du和df来获取目录或文件系统已占用空间的情况.但它们的统计结果是不一致的,大多 ...
- Python-Tkinter 使用for循环生成列表式Button及函数调用
Tkinter是轻量级的图形化界面,在使用中我们可能遇到需要生成一串Button按钮的情况,如图: 如果一个一个操作就太麻烦了,但我们可以通过for循环列表的形式来实现 来看看以下例子: from t ...
- java面试-生产环境服务器变慢,谈谈你的诊断思路
1.uptime:查询linux系统负载 11:16:16 系统当前时间 up 64 days, 19:23 从上次启动开始系统运行的时间3 users 连接数量,同一用户多个连接的时候算多个load ...
- Dynamics CRM制作报表的时候让用户可以用自己的权限浏览数据
我们做SSRS报表的时候最头疼的问题就是用Sql查出来的数据都是全部数据没有做权限过滤,导致不同用户看到的数据是一样的. 确实Dynamics CRM产品的数据库时有对这个做处理的,其中每个实体都会有 ...
- OO UNIT 2 个人总结
第二单元面向对象作业--性感电梯在线吃人 Part 1:单部可捎带电梯 多线程设计策略 本次电梯仅仅只有一部运行,因此,在多线程的设计中难度不大,并且,只需采用一对一的生产者-消费者模型即可解决问题. ...
- Elasticsearch核心技术与实战,性能是真牛
Elasticsearch 是一款非常强大的开源搜索及分析引擎.结合 Kibana.Logstash和Beats,Elasticsearch 还被广泛运用在大数据近实时分析,包括日志分析.指标监控.信 ...
- C++运算符重载的一些困惑
一.背景 在复习<C++基础与提高>时,自己实现运算符重载(i++)时,几次都报错.其实还是自己对运算符重载这一部分内容理解得不够透彻,于是再次看了下书上的内容,理解算是加深了一些,于是提 ...