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. kmp&字典树 模板

    kmp: const int maxn=1e5+5; char s[maxn],p[maxn]; int nex[maxn]; int KmpSearch(char* s, char* p) { in ...

  2. GUI编程学习笔记——day01

    GUI编程 前言:告诉大家应该怎么学? 这是什么? 它怎么玩? 该如何在我们平时运用? 组件 窗口 弹窗 面板 文本框 列表框 按钮 图片 监听事件 鼠标 键盘事件 破解工具 一.是什么 GUI是图形 ...

  3. Java中BO、DAO、DO、DTO、PO、POJO、VO的概念

    在程序开发中,经常会碰到各种专业术语,这里统一做一下解释,有遗漏或理解错误的恳请指正. BO(Business Object)业务对象 主要作用是把业务逻辑封装为一个对象,这个对象可以包括一个或多个其 ...

  4. 走进docker-聊聊docker网络

    容器网络概念 首先了解下linux的网络构成概念 命名空间: Linux在网络栈中引入网络命名空间,将独立的网络协议栈隔离到不同的命令空间中,彼此间无法通信:Docker利用这一特性,实现不容器间的网 ...

  5. Java例题_39 判断奇偶后分数累加

    1 /*39 [程序 39 分数累加] 2 题目:编写一个函数,输入 n 为偶数时,调用函数求 1/2+1/4+...+1/n,当输入 n 为奇数时,调用函数 3 1/1+1/3+...+1/n 4 ...

  6. java例题_25 判断是否为回文数!

    1 /*25 [程序 25 求回文数] 2 题目:一个 5 位数,判断它是不是回文数.即 12321 是回文数,个位与万位相同,十位与千位相同. 3 */ 4 5 /*分析 6 * 先用%和/将5个数 ...

  7. 如何在Google Web Toolkit环境下Getshell

    出品|MS08067实验室(www.ms08067.com) 本文作者:大盗贼卡卡 Google Web Toolkit简称(GWT),是一款开源Java软件开发框架.今天这篇文章会介绍如何在这样的环 ...

  8. SqlServer触发器的创建与使用

    前言 上期我们介绍了SqlServer的视图和存储过程创建与使用,这期我们介绍一下触发器. 有需要回顾的可以电梯直达看一下: SqlServer视图的创建与使用 SqlServer存储过程的创建与使用 ...

  9. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...

  10. ATMS中去拉起新的进程,并在新进程启动后调用attachApplication时,resume待启动的Activity

    相关文章: ATMS中去pause Activity A. 目录 ATMS拉起新进程 堆栈 resumeTopActivityInnerLocked:1684, ActivityStack start ...