HDU1877-又一版 A+B
2015-11-22 16:33
190 查看
Problem Description
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。当m为0时输入结束。
Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。Sample Input
8 1300 48 2 1 7 0
Sample Output
2504 1000 水题,注意格式问题和a+b和为0的情况 代码如下#include <stdio.h> #include <stdlib.h> #include <math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { long long a,b; int i,m,j; int c[100]; while((scanf("%d%lld%lld",&m,&a,&b)!=-1)&&m!=0) { a=a+b; if(a==0) { printf("0"); } for(i=0;a!=0;i++) { c[i]=a%m; a/=m; } for(j=i-1;j>=0;j--) { printf("%d",c[j]); } printf("\n"); } return 0; }
相关文章推荐
- 解析错误:解析软件包时出现问题
- QT5与之前版本间问题整理
- 大白-Dijksta模板
- 分层设计
- java 每日习题(九)从数据库中取数据
- Extjs的架构设计思考,单页面应用 or 多页面?
- include与jsp:include区别
- HDU 1008-Elevator
- HDU 5569 长度为n的上升子序列个数d (大数模板+DP)
- 线索二叉树
- android studio使用教程(二)常用的设置
- web学习-jsp客户端与Servlet的关联
- 前序遍历的层号表示转孩子数组表示法
- QTime中currentTime()的使用方法
- Hbuilder--让手爽,飞一般的编码(二)
- MAC bootstrap-cms安装记录
- JSP__通过a标签传递参数 用getParameter 获取参数
- poj1125Stockbroker Grapevine【最短路】
- hdu 1016 Prime Ring Problem dfs
- Nim Game (Leet Code)