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. P1200_你的飞碟在这儿(JAVA语言)

    题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者. 不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带 ...

  2. 攻防世界 reverse reverse-for-the-holy-grail-350

    reverse-for-the-holy-grail-350   tu-ctf-2016 程序流程很简单,就一个检验函数: 1 __int64 __fastcall stringMod(__int64 ...

  3. OLAP引擎:基于Druid组件进行数据统计分析

    一.Druid概述 1.Druid简介 Druid是一款基于分布式架构的OLAP引擎,支持数据写入.低延时.高性能的数据分析,具有优秀的数据聚合能力与实时查询能力.在大数据分析.实时计算.监控等领域都 ...

  4. (原创)高DPI适配经验系列:(二)按DPI范围适配

    一.前言 一个软件,往往会用到位图资源,比如图标.图片.水晶按钮等. 在使用了位图资源后,就不能对任意DPI都进行适配,因为这样适配的代价太大了. 像Win10的缩放比例可以由100%-500%,如果 ...

  5. Dynamics CRM实体系列之窗体

    本节开始讲Dynamics CRM的窗体排版和设计,窗体也就是我们实际可以看到的表单界面.Dynamics CRM提供了一套独立的表单模板设计引擎,可以很方便的为开发者提供无代码开发,只需要简单的拖动 ...

  6. 关于ArrayList 中子方法 -- contains 疑惑解决

    写之前先看下 ArrayList 子函数 contains 的Api 怎么介绍: boolean contains(Object o)           如果此列表中包含指定的元素,则返回 true ...

  7. python程序—一键部署keepalived+lvs

    一个DS 两个RS keepalived端在/root下准备好已经修改好的配置文件 import paramiko # keepalived端 需要修改的信息 keepalived_ip='192.1 ...

  8. 亮相 LiveVideoStackCon,透析阿里云窄带高清的现在与未来

    2021.4.16-4.17,阿里云视频云亮相 LiveVideoStackCon 音视频技术大会上海站,带来三场不同视角的主题演讲,并与众多行业伙伴一同交流.在 "编解码的新挑战与新机会& ...

  9. Spring Cloud Alibaba(4)---Nacos(注册中心)

    Nacos(注册中心) 有关Spring Cloud Alibaba之前写过三篇文章. Spring Cloud Alibaba(1)---入门篇 Spring Cloud Alibaba(2)--- ...

  10. .NET6 平台系列4 .NET开源之路

    系列目录     [已更新最新开发文章,点击查看详细] .NET平台是微软于2000年推出的Windows操作系统的应用软件开发框架,发展至今形成巨大的技术栈,涉及多语言(支持C#.F#.VB.NET ...