HDU 1877 又一版 A+B
来源:互联网 发布:solidworks有mac版吗 编辑:程序博客网 时间:2024/05/20 02:23
http://acm.hdu.edu.cn/showproblem.php?pid=1877
又一版 A+B
Time Limit: 2000/1000 MS(Java/Others)
Total Submission(s):8509
Problem Description
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m(1 < m <10)进制数。
Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。
当m为0时输入结束。
当m为0时输入结束。
Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。
Sample Input
8 1300 48 21 7 0
Sample Output
25041000
Author
ZJU
Source
浙大计算机研究生复试上机考试-2008年
分析:一道简单题,需要注意的是最后输出的a+b有可能超过int的范围。进制转换时,a+b可能==0;
代码如下:
#include<stdio.h>
#include<string.h>
int ans[1000];
int fun(__int64 a,int m)
{
int i=0;
while(a)
{
ans[i++]=a%m;
a=a/m;
}
return i;
}
int main()
{
int m;
int a,b,l,i;
__int64 c;
while(scanf("%d",&m),m)
{
scanf("%d%d",&a,&b);
c=a+b;
if(!c)
{
printf("0\n");
continue; //千万别写成break。。在这里wrong了好多次。。唉。。
}
l=fun(c,m);
for(i=l-1;i>=0;i--)
printf("%d",ans[i]);
printf("\n");
}
return 0;
}
#include<string.h>
int ans[1000];
int fun(__int64 a,int m)
{
}
int main()
{
}
阅读全文
0 0
- HDU 1877 又一版 A+B
- hdu 1000 A + B Problem
- (HDU)1228 A+B
- hdu 1040 As Easy As A+B
- HDOJ 2101 A + B Problem Too
- fzu 1759 A^B % C
- HDOJ 2075 A|B?
- HDOJ 2034 人见人爱A-B
- 2057A + B Again
- sum a b
- HDOJ 2054 A == B ?
- HDU 2102 A计划
- HDOJ 1040 As Easy As A+B
- HDOJ 2503 a/b + c/d
- A + B Problem II
- hdu 1097 A hard puzzle
- hdu 1097 A hard puzzle
- HDU 1339 A Simple Task
- Tomcat 可以localhost访问,但不能127.0.0.1访问(转)
- HDU 1977 Consecutive sum II
- HDU 1976 Software Version
- 移动端布局页面实现
- angularjs表头排序
- HDU 1877 又一版 A+B
- HDU 1862 EXCEL排序
- HDU 1859 最小长方形
- HDU 1799 循环多少次?
- web项目部署到Tomcat上使用
- HDU 1785 You Are All Excellent
- HDU 1718 Rank
- HDU 1708 Fibonacci String
- HDU 1555 How many days?