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 ...
随机推荐
- event事件学习小节
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- rman恢复误删除的一张表(不完全恢复)
恢复误删除的一张表可以使用很多方法,如日志挖掘.闪回等,rman恢复(不完全恢复)肯定不是最好的,也不建议用, 现在我们只是演示一下这种恢复. 1 RMAN备份数据库 2创建测试表 3查看此时的SCN ...
- 解决微信浏览器无法使用window.location.reload()刷新页面
解决方法: 使用 window.location.href=window.location.href+随机数 代替 window.location.reload(). function r ...
- BizTalk2010动手实验(二)第一个BizTalk应用
1 课程简介 通过本课程了解BizTalk 的消息机制,发布与订阅机制 2 准备工作 3 操作步骤 3.1 创建BizTalk应用程序 1. 新建应用程序 2. 输入应用程序名称 3.2 创建与配置接 ...
- BizTalk开发系列(三十二)浅谈BizTalk主机性能优化
很多BizTalk的项目都要考虑到性能优化的问题,虽然BizTalk采用多线程处理消息的,大大提高了程序效率.但默认情况下 BizTalk的主机有很多阻止参数会控制BizTalk对服务器的资源使用率, ...
- C语言100道经典算法
经典的100个c算法 C语言的学习要从基础,100个经典的算法真不知道关于语言的应该发在那里,所以就在这里发了,发贴的原因有2个,第一个,这东西非常值得学习,第二个,想..........嘿嘿,大家应 ...
- AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
在使用SqlConnection.Open()连接到SQL Server 2008 R2 SP2时,一直报以下异常: AccessViolationException: 尝试读取或写入受保护的内存.这 ...
- C#整数三种强制类型转换int、Convert.ToInt32()、int.Parse()的区别
1.int适合简单数据类型之间的转换,C#的默认整型是int32(不支持bool型); 2.int.Parse(string sParameter)是个构造函数,参数类型只支持string类型; 3. ...
- Given a compiled machine-language program, which statements in the source language cause the execution of the most machine-language instructions and what is the execution time of these instr
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION A variety of studi ...
- js中eval() 方法的使用以及一些特殊的使用方式
1.eval方法只能在非严格模式中进行使用,在use strict中是不允许使用这个方法的. 2.eval函数接收一个参数s,如果s不是字符串,则直接返回s.否则执行s语句.如果s语句执行结果是一个值 ...