首页 > 其他 > 详细

hdu 1877 又一版 A+B

时间:2015-11-18 22:39:36      阅读:234      评论:0      收藏:0      [点我收藏+]

又一版 A+B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14701    Accepted Submission(s): 5618


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后会超出int型
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LL long long
int s[100100];
int main()
{
	int m,a,b;
	LL n;
	int k;
	while(scanf("%d",&m),m)
	{
		scanf("%d%d",&a,&b);
		n=a+b;
		if(n<=0)
		{
			printf("0\n");
			continue;
		}
		LL x=n;
		k=0;
		memset(s,0,sizeof(s));
		while(x)
		{
			s[k++]=x%m;
			x/=m;
		}
		for(int i=k-1;i>=0;i--)
	    	printf("%d",s[i]);
	    printf("\n");
	}
	return 0;
} 

  

hdu 1877 又一版 A+B

原文:http://www.cnblogs.com/tonghao/p/4975951.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!