九度OJ 1143:Primary Arithmetic(初等数学) (进位)
2015-10-24 12:37
309 查看
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:616
解决:254
题目描述:
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.
样例输入:
样例输出:
来源:2009年北京大学计算机研究生机试真题
思路:
求两数相加的进位次数。
代码:
内存限制:32 兆
特殊判题:否
提交:616
解决:254
题目描述:
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.
样例输入:
123 456 555 555 123 594 0 0
样例输出:
NO carry operation. 3 carry operations. 1 carry operation.
来源:2009年北京大学计算机研究生机试真题
思路:
求两数相加的进位次数。
代码:
#include<stdio.h> int a,b; int main() { while(scanf("%d%d",&a,&b)!=EOF) { int c=0; int k=0; if(a==0&&b==0) break; while(a!=0&&b!=0) { c=(a%10+b%10+c)/10; if(c>=1) k++; a/=10; b/=10; } if(k==0) printf("NO carry operation.\n"); else if(k==1) printf("%d carry operation.\n",k); else printf("%d carry operations.\n",k); } return 0; } /************************************************************** Problem: 1143 User: liangrx06 Language: C Result: Accepted Time:0 ms Memory:912 kb ****************************************************************/
相关文章推荐
- Python __name__ == '__main__' 介绍
- FL2440如何利用JLINK烧写U-boot到NAND Flash中
- 指针指向类的静态数据成员
- 面向切面编程AOP作用
- 理解事件流及事件对象
- Activity(undone)
- linux下打开、关闭tomcat,实时查看tomcat运行日志
- codevs 1183 泥泞的道路
- js模块加载之AMD和CMD
- U-boot-2010.09移植(六)NAND Flash启动支持
- C++函数指针简介
- C++函数指针简介
- [原]Android Studio使用极光推送出现at cn.jpush.android.service.ServiceInterface.a(Unknown Source) 已解决
- Hibernate-映射关系- n->1(单向)
- FL2440的U-boot-2009.08移植(五)uboot架构中NAND Flash驱动修改
- POJ 1182——食物链——————【种类并查集】
- Corona的工程配置
- FL2440的U-boot-2009.08移植(四) 支持DM900网卡
- hdoj 2063 过山车 【双边匹配匈牙利算法】
- 设计模式之Builder模式