1350. 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.
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.
Sample Input
123 456
555 555
123 594
0 0
Output for Sample Input
No carry operation.
3 carry operations.
1 carry operation.
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
unsigned int m,n,sum,i;
//cin>>m>>n;
while(cin>>m>>n)
{
if(m==&&n==)
break;
unsigned int temp;
if(m<n)
{
temp=m;
m=n;
n=temp;
}
unsigned int m1,n1;
i=;
sum=;
while(m>)
{
m1=m%;
n1=n%;
if(m1+n1+i>=)
{
i=;
sum++;
}
else {
i=;
}
m=m/;
n=n/; }
while(n>)
{
if(n%+i>=)
{
i=;
sum++;
}
else
{
i=;
}
n=n/;
}
if(sum==)
{
cout<<"No carry operation."<<endl;
}
else if(sum==)
{
cout<<sum<<" carry operation."<<endl;
}
else if(sum>)
{
cout<<sum<<" carry operations."<<endl;
}
//cin>>m>>n;
}
return ;
}
1350. Primary Arithmetic的更多相关文章
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- 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 ...
- 九度OJ 1143:Primary Arithmetic(初等数学) (进位)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:616 解决:254 题目描述: Children are taught to add multi-digit numbers from ri ...
- 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年半年时间完成 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- zoj 1874 水题,输出格式大坑
Primary Arithmetic Time Limit: 2 Seconds Memory Limit: 65536 KB Children are taught to add mult ...
随机推荐
- form表单提交controller层接收到的值为乱码的问题
今天遇到个中文乱码问题,大体情况是这样的:前台有一个form表单,其中有几个input的控件,值是带中文的,form表单只设置了id='form1' method='post' action='xx ...
- Struts基础详解
1.web.xml配置: <filter> <filter-name>Struts2</filter-name> <filter-class> org. ...
- IOS第16天(5,Quartz2D雪花)
*** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...
- php解析一个url
$url = "http://shopnc.localhost/shop/index.php?act=goods&op=index&goods_id=25220"; ...
- apache查看工作模式及调优
一,查看工作模式 /usr/sbin/httpd -l Compiled in modules: core.c prefork.c http_core.c mod_so.c 如果出现prefo ...
- (转)php自己创建框架
前言 说到写PHP的MVC框架,大家想到的第一个词--“造轮子”,是的,一个还没有深厚功力的程序员,写出的PHP框架肯定不如那些出自大神们之手.经过时间和各种项目考验的框架.但我还是准备并且这么做了, ...
- iOS中集成ijkplayer视频直播框架
ijkplayer 是一款做视频直播的框架, 基于ffmpeg, 支持 Android 和 iOS, 网上也有很多集成说明, 但是个人觉得还是不够详细, 在这里详细的讲一下在 iOS 中如何集成ijk ...
- centos7下更改java环境
1.上传下载的java包,如http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jre-8u77-linux-x64.rpm,目录可以自己定义一个 ...
- validate 的插件用法
1.不推荐使用控件方式验证的方式(因为他严重的影响的html代码,也不便于语义化) <input type="text" class="required" ...
- rndc控制远程dns服务器配置方法
1- 如果不存在/etc/rndc.conf touch /etc/rndc.conf chown named:named /etc/rndc.conf 2- rndc-confgen > /e ...