时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:616

解决:254

题目描述:

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.

输入:

Each line of input contains two unsigned integers less than 10 digits. The last line of input contains 0 0.

输出:

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.

样例输入:
123 456
555 555
123 594
0 0
样例输出:
NO carry operation.
3 carry operations.
1 carry operation.
来源:
2009年北京大学计算机研究生机试真题

思路:

求两数相加的进位次数。

代码:

#include<stdio.h>
int a,b;
int main()
{
while(scanf("%d%d",&a,&b)!=EOF)
{
int c=0;
int k=0;
if(a==0&&b==0)
break;
while(a!=0&&b!=0)
{
c=(a%10+b%10+c)/10;
if(c>=1)
k++;
a/=10;
b/=10;
}
if(k==0)
printf("NO carry operation.\n");
else if(k==1)
printf("%d carry operation.\n",k);
else
printf("%d carry operations.\n",k);
} return 0;
}
/**************************************************************
Problem: 1143
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/

九度OJ 1143:Primary Arithmetic(初等数学) (进位)的更多相关文章

  1. 【九度OJ】题目1113:二叉树 解题报告

    [九度OJ]题目1113:二叉树 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1113 题目描述: 如上所示,由正整数1,2,3-- ...

  2. 【九度OJ】题目1442:A sequence of numbers 解题报告

    [九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...

  3. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  4. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

  5. 九度OJ,题目1089:数字反转

    题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...

  6. 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)

    题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...

  7. 九度OJ 1531 货币面值(网易游戏2013年校园招聘笔试题) -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1531 题目描述: 小虎是游戏中的一个国王,在他管理的国家中发行了很多不同面额的纸币,用这些纸币进行任意的组合可以在 ...

  8. 九度OJ 1024 畅通工程 -- 并查集、贪心算法(最小生成树)

    题目地址:http://ac.jobdu.com/problem.php?pid=1024 题目描述:     省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...

  9. 九度OJ 1371 最小的K个数 -- 堆排序

    题目地址:http://ac.jobdu.com/problem.php?pid=1371 题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4 ...

随机推荐

  1. 【CF56E】Domino Principle(线性扫描,伪DP)

    每块多米诺骨牌所在的位置设为x,每块多米诺骨牌高度为h.如果将x位置上的多米诺骨牌向右翻到,它就可以影响[x+1, x+h-1]范围内的所有多米诺骨牌,让他们也翻到,同时这些被翻到的多米诺骨牌还能影响 ...

  2. C语言的二次实验报告

    题目一 题目二 题目三 题目四 题目五 部分源代码 11-1求矩阵的局部极大值 #include<stdio.h>int main(){    int m,n,i=0,j=0,count= ...

  3. CSS3动画那么强,requestAnimationFrame还有毛线用--摘抄

    CSS3动画那么强,requestAnimationFrame还有毛线用? 这篇文章发布于 2013年09月30日,星期一,19:12,归类于 web综合. 阅读 197124 次, 今日 84 次 ...

  4. Object 转 String

    做项目中 : map 为Map<String,Object> a.setmoney(new BigDecimal((String)map.get("money"))); ...

  5. POJ2104Kth Number

    整体二分模板题, 有些细节需要注意 #include<cstdio> #include<cctype> #include<climits> #include< ...

  6. Java中获取ServletContext的方法

    Servlet: this.getServletContext() this.getServletConfig().getServletContext() request.getSession().g ...

  7. System.Length 函数

    function _PCharLen(P: _PAnsiChr): Longint;{$IFNDEF LEGACY_PCHARLEN}begin  Result := 0;  if P <> ...

  8. 【js】前台调试,在浏览器调试环境下找不到js怎么办?

    针对这次 整个项目单页面的情况下,所有点击出现的新页面都是追加在母页面的情况下,很多时候不像原本的情况,可以直接在浏览器的调试环境下找到想要调试的js代码 这种情况下,怎么能找到子页面的js代码,调试 ...

  9. iOS -- SKTransition类

      SKTransition类 继承自 NSObject 符合 NSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit.framewor ...

  10. android特效集合

    https://github.com/Trinea/android-open-project http://www.cnblogs.com/hawkon/p/3593709.html http://i ...