加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

(高精度运算4.7.24)UVA 10013 Super long sums(大数加法——某一

发布时间:2020-12-14 03:57:00 所属栏目:大数据 来源:网络整理
导读:/* * UVA_10013.cpp * * Created on: 2013年10月29日 * Author: Administrator */#include iostream#include cstdio#include cstringusing namespace std;int ans[1000005];int main() {int t;scanf("%d",t);while (t--) {memset(ans,sizeof(ans));int M;sca
/*
 * UVA_10013.cpp
 *
 *  Created on: 2013年10月29日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int ans[1000005];

int main() {
	int t;
	scanf("%d",&t);
	while (t--) {
		memset(ans,sizeof(ans));

		int M;
		scanf("%d",&M);
		int j;

		for (j = M - 1; j >= 0; --j) {//由高位到底为处理一遍
			int num1,num2;
			scanf("%d%d",&num1,&num2);

			ans[j] += num1 + num2;
			ans[j + 1] += ans[j] / 10;
			ans[j] %= 10;
		}

		for(j = 0 ; j < M ;++j){//由地位到高位处理一遍
			ans[j+1] += ans[j]/10;
			ans[j] %= 10;
		}
		if (ans[M]) {//判断最高位是否有进位
			M++;
		}

		for (j = M - 1; j >= 0; --j) {//由高位到低位输出结果
			printf("%d",ans[j]);
		}
		printf("n");
		if (t > 0) {
			printf("n");
		}
	}
	return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读