BNUOJ 1006 Primary Arithmetic
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的更多相关文章
- POJ 2562:Primary Arithmetic
Primary Arithmetic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11135 Accepted: 40 ...
- UVA OJ 10035 - Primary Arithmetic
Primary Arithmetic Children are taught to add multi-digit numbers from right-to-left one digit at a ...
- 1350. Primary Arithmetic
Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find th ...
- 九度OJ 1143:Primary Arithmetic(初等数学) (进位)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:616 解决:254 题目描述: Children are taught to add multi-digit numbers from ri ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Zerojudge解题经验交流
题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- zoj 1874 水题,输出格式大坑
Primary Arithmetic Time Limit: 2 Seconds Memory Limit: 65536 KB Children are taught to add mult ...
随机推荐
- HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)
题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...
- JS对于Android和IOS平台的点击响应的适配
IOS点击事件 Click 300毫秒点击延迟 解决办法: 参考:http://cuiqingcai.com/1687.html 可判断设备 if (/(iPhone|iPad|iPod|iOS)/i ...
- C++学习笔记15:操作符重载的函数原型列表(推荐)
//普通四则运算 friend A operator +(const A & lhs, const A & rhs); friend A operator -(const A & ...
- sprintf 用法
字符串格式化命令,主要功能是把格式化的数据写入某个字符串中 试试下面的代码就知道了 #include<cstdio> #include<cstdlib> using names ...
- 纯JavaScrip图表插件——Highcharts
简介 Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用.目前H ...
- zookeeper的 目录加密
import org.apache.zookeeper.CreateMode;import org.apache.zookeeper.WatchedEvent;import org.apache.zo ...
- POJ1637 Sightseeing tour (混合图欧拉回路)(网络流)
Sightseeing tour Time Limit: 1000MS Me ...
- 简单三步-实现dede站内搜索功能
第一步:找到对应的搜索模板的代码 我们都知道,dede有自带的搜索功能,我们只要找到对应的模板,然后把我们想要的代码拿出来就行了.具体如下: 首先进入templets-->default--&g ...
- 越狱Season 1-Episode 12:Odd Man Out
Season 1-Episode 12:Odd Man Out -Sorry to keep you waiting. 抱歉让你等了半天 -Oh, it's, uh, not a problem. 嗯 ...
- 点亮LED(库函数实现)
本次测试采用的芯片是STM32F103CB 我的开发板如下: 此开发板有8个led,分别为D11,D12,D13,D14,D15,D16,D17,D18.查询核心板的电路图后知道其对应芯片的控制引脚为 ...