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 ...
随机推荐
- Python图像处理库——PIL
PIL全称Python Image Library,是python官方的图像处理库,包含各种图像处理模块.Pillow是PIL的一个派生分支,包含与PIL相同的功能,并且更灵活.python3.0之后 ...
- Alluxio+HDFS+MapReduce集成及测试
目录 1.在 HDFS 上配置 Alluxio 1.1.节点角色 1.2.软件版本 1.3.准备工作 1.3.1.设置 SSH 免密登录 1.3.2.安装 JDK 1.3.3.安装 Hadoop 1. ...
- GitlabCI/CD&Kubernetes项目交付流水线实践
GitlabCI实践 GitLabCI/CD基础概念 为什么要做CI/CD? GitLab CI/CD简介 GitLabCI VS Jenkins 安装部署GitLab服务 GitLabRunner实 ...
- 学习笔记-cordova 限制app横屏
禁止手机app横竖屏幕转换,只需在根目录下的 config.xml 中添加如下内容 <preference name="orientation" value="po ...
- 问题笔记 - element表格 操作状态值
1.必须从传到表里的数据源中取值(scope.row.star)
- JVMGC+Spring Boot生产部署和调参优化
一.微服务开发完成,IDEA进行maven clean和package 出现BUILD SUCCESS说明打包成功 二.要求微服务启动时,配置JVM GC调优参数 p.p1 { margin: 0; ...
- 【转载】C# get 与set的一些说明
转载 在面向对象编程(OOP)中,是不允许外界直接对类的成员变量直接访问的,既然不能访问,那定义这些成员变量还有什么意义呢?所以C#中就要用set和get方法来访问私有成员变量,它们相当于外界访问对象 ...
- BUAA_OO_第二单元
BUAA_OO_2020_UNIT2 一.程序结构分析 第五次作业 UML & Mertrics 电梯的调度问题,实质上就是任务的请求与分配问题,笔者在第五次作业中采用简单的"生 ...
- docker之镜像配置
以管理员sudo执行以下命令 docker ps -a 查看镜像的id docker exec -it 镜像id /bin/bash -i表示交互模式 -t表示启动容器进入命令行 加入这两参数,容器创 ...
- 8-50.Pow(x,n)
题目描述: 解题思路: 第一想法是递归,结果f(x,n) = x * f(x,n-1);这种方法的空间复杂度太高了,太想当然. 看了下题解:采取分治的方法:f(x,n) = f(x,n/2) * f( ...