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 ...
随机推荐
- Android.mk 常用宏和变量
android ndk开发有一个重要的文件 Android.mk,他虽然重要,但是对它进行深入介绍的文档却比较的少,这里将对Android.mk中常用的宏和变量进行说明: 由于这一部分的内容多,资料零 ...
- 解决:HotSeat短信图标提醒有误
[操作步骤]正常收发短信.彩信. [测试结果]所有短信均已阅读,但在HOME界面的短信图标仍提示有一条短信未读.重启后仍存在. 经过分析,导致该情况的主要原因为当彩信已读的时候,launcher中进行 ...
- 12、SQL基础整理(运算符与优先级)
运算符 + - * / %(取余),赋值运算符 = declare @jia int set @jia = 1+1 print @jia declare @jia int set @jia = 10% ...
- Cryptography加密和解密
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Se ...
- web字体
<span style="font-family:sans-serif">Lorem Ipsum</span> <span style="f ...
- Inno Setup 插件大全
Inno Setup 插件大全 这是我收集到的目前网上最全的插件之一,里面的每个插件,都有详细的脚本示例来讲解该插件的具体用法.另外,下载了我公开的脚本的朋友,也有可能会被提示缺少文件,如果缺 ...
- 第一次div1做出3道题
第一次div1做出3道题! 再接再厉! 哈利路亚!
- 101+ Manual and Automation Software Testing Interview Questions and Answers
101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...
- postgresql 分区表创建及测试
1 建立分区 1.1. 创建主表 CREATE TABLE measurement ( city_id int not null, logdate date ...
- DataTableToExcel
public static string CreateExcel(DataTable dt, string FileName, string path, string columns) ...