Primary Arithmetic

来源:BNUOJ 1006
http://www.bnuoj.com/v3/problem_show.php?pid=1006

当你在小学学习算数的时候,老师会教你把两个数由右至左按位加起来。
很多时候,加法过程中会出现进位。对于一部分孩子,理解这个“进位”
在当时是很困难的事情。现在你的工作就是编写一个程序来判断两个数
相加的过程中会产生多少次进位,用以确定这两个数相加的“难度”。
Input
每一行有两个无符号整数(最大不超过1000000000),当输入0 0的时候,程序结束。
Output
对于每一行的输入两个整数,你需要判断会产生有多少个进位,每一个输出占一行。
Sample Input Sample Output
No carry operation.
carry operations.
carry operation. Source
第七届北京师范大学程序设计竞赛热身赛第一场 ()注意输出结果里面的细微区别:
operations和operation
()这个题目大多数人可能会想:直接把两个数当字符串输入再从后往前扫描处理。
其实这个题可以重复下面的过程:取余数直接得到最低位,然后消掉最低位。

题目描述

 #include<stdio.h>
int main()
{
int a,b,x,y,c;
int result;
freopen("input.txt","r",stdin);
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a==&&b==) break;
result=;
c=;
while(a>||b>)
{
x=a%;
y=b%;
a=a/;
b=b/;
c=x+y+c;
if(c>=)
{
result++;
c=c/;
}
else
{
c=;
}
}
if(result==) printf("No carry operation.\n");
else
{
if(result>) printf("%d carry operations.\n",result);
else printf("%d carry operation.\n",result);
}
}
return ;
}

BNUOJ 1006 Primary Arithmetic的更多相关文章

  1. POJ 2562:Primary Arithmetic

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

  2. UVA OJ 10035 - Primary Arithmetic

    Primary Arithmetic Children are taught to add multi-digit numbers from right-to-left one digit at a ...

  3. 1350. Primary Arithmetic

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

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

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

  5. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  6. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  7. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  8. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  9. zoj 1874 水题,输出格式大坑

    Primary Arithmetic Time Limit: 2 Seconds      Memory Limit: 65536 KB Children are taught to add mult ...

随机推荐

  1. ios上 更改 状态栏(UIStatusBar)

    摘要 ios上 更改状态栏(UIStatusBar)的颜色 ios UIStatusBar statusBar 状态栏 更改状态栏颜色 目录[-] IOS上 关于状态栏的相关设置(UIStatusBa ...

  2. 微信分享 添加URL Schemes

    1. TARGETS - Info - URL Types identifier -> weixin URL Schemes -> 应用id 2.在AppDelegate.h 引入头文件 ...

  3. UIKit框架之UIlabel

    1.继承链:UIview:UIresponder:NSObject 2.如果你想要使UIlabel能够和用户进行互动,需要把它实例变量的属性 userInteractionEnabled改为yes 3 ...

  4. BZOJ 4723 Flappy Bird

    找到可行区间,最优解一定在区间的下端点. #include<iostream> #include<cstdio> #include<cstring> #includ ...

  5. GridView按钮事件

    1.html代码 <asp:TemplateField HeaderText="操作"> <ItemTemplate> <div style=&quo ...

  6. Codechef2015 May - Chef and Strings (后缀自动机)

    用后缀自动机统计出出现1~n次的串的数量f[i] 对于ans[k]=sigma(f[i]*C(i,k)) i>=k ; mo=; ..maxn] of dword; nt:..maxn,'a'. ...

  7. PHP Mail 简介

    PHP mail() 函数用于从脚本中发送电子邮件. mail(to,subject,message,headers,parameters): 参数 描述 to 必需.规定 email 接收者. su ...

  8. "Your local changes to the following files would be overwritten by merge" on git

    运行: git merge --ff origin/master 得到错误信息: error: Your local changes to the following files would be o ...

  9. LeetCode Search a 2D Matrix II (技巧)

    题意: 有一个矩阵,每行有序,每列也有序.判断一个数target是否存在于此矩阵中. 思路: 从右上角开始,如果当前数字<target,则该行作废.若当前数字>target,该列作废.这样 ...

  10. python发布文件(windows)

    怎样发布文件 首先发布本地文件有一个好的用处,就是省去了朋友同import的时候还要使用sys.path,省的自己出错 1.新建文件夹d:\ tool 在的d:\tool文件夹中建立login.py ...