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的更多相关文章

  1. BNUOJ 1006 Primary Arithmetic

    Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...

  2. POJ 2562:Primary Arithmetic

    Primary Arithmetic Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11135   Accepted: 40 ...

  3. 九度OJ 1143:Primary Arithmetic(初等数学) (进位)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:616 解决:254 题目描述: Children are taught to add multi-digit numbers from ri ...

  4. UVa OJ 458

     The Decoder  Write a complete program that will correctly decode a set of characters into a valid m ...

  5. UVA OJ 623 500!

    500!  In these days you can more and more often happen to see programs which perform some useful cal ...

  6. uva oj 567 - Risk(Floyd算法)

    /* 一张有20个顶点的图上. 依次输入每个点与哪些点直接相连. 并且多次询问两点间,最短需要经过几条路才能从一点到达另一点. bfs 水过 */ #include<iostream> # ...

  7. 1350. Primary Arithmetic

    Children are taught to add multi-digit numbers from right-to-left one digit at a time.  Many find th ...

  8. UVa OJ 194 - Triangle (三角形)

    Time limit: 30.000 seconds限时30.000秒 Problem问题 A triangle is a basic shape of planar geometry. It con ...

  9. UVa OJ 175 - Keywords (关键字)

    Time limit: 3.000 seconds限时3.000秒 Problem问题 Many researchers are faced with an ever increasing numbe ...

随机推荐

  1. Day2:Windows常用快捷键与基本的Dos命令

    Windows常用快捷键 必须掌握: Ctrl+C:复制 Ctrl+V:粘贴 Ctrl+Z:撤销 Ctrl+S:保存 Win键+R:运行(run) alt+F4:关闭窗口/页面 Ctrl+A:全选 C ...

  2. 第一个win32程序

    vs2017下自动创建的窗口程序 // win_test.cpp : 定义应用程序的入口点. // #include "framework.h" #include "wi ...

  3. PTA 找出不是两个数组共有的元素

    7-2 找出不是两个数组共有的元素 (20 分)   给定两个整型数组,本题要求找出不是两者共有的元素. 输入格式: 输入分别在两行中给出两个整型数组,每行先给出正整数N(≤),随后是N个整数,其间以 ...

  4. MySQL数据库与python交互

    1.安装引入模块 安装mysql模块 pip install PyMySQL; 文件中引入模块 import pymysql 2.认识Connection对象 用于建立与数据库的连接 创建对象:调用c ...

  5. JS定时器使用,定时定点,固定时刻,循环执行

    JS定时器使用,定时定点,固定时刻,循环执行 本文概述:本文主要介绍通过JS实现定时定点执行,在某一个固定时刻执行某个函数的方法.比如说在下一个整点执行,在每一个整点执行,每隔10分钟定时执行的方法. ...

  6. istio: 无法提供内部访问外部服务

    现象 能够内部无法访问外部服务. 在部署测试服务 kubectl apply -f samples/sleep/sleep.yaml 设置环境变量 export SOURCE_POD=$(kubect ...

  7. ClickHouse性能优化?试试物化视图

    一.前言 ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS):目前我们使用CH作为实时数仓用于统计分析,在做性能优化的时候使用了 物化视图 这一特性作为优化手段,本文主 ...

  8. SparkStreaming使用mapWithState时,设置timeout()无法生效问题解决方案

    前言 当我在测试SparkStreaming的状态操作mapWithState算子时,当我们设置timeout(3s)的时候,3s过后数据还是不会过期,不对此key进行操作,等到30s左右才会清除过期 ...

  9. SpringBoot项目war包部署

    服务部署 记录原因 将本地SpringBoot项目通过war包部署到虚拟机中,验证服务器部署. 使用war包是为了方便替换配置文件等. 工具 对象 版本 Spring Boot 2.4.0 VMwar ...

  10. buuctf pwn wp---part1

    pwn难啊 1.test_your_nc 测试你nc,不用说,连上就有. 2.rip ida中已经包含了system函数: 溢出,覆盖rip为fun函数,peda计算偏移为23: from pwn i ...