zoukankan      html  css  js  c++  java
  • (高精度运算4.7.24)UVA 10013 Super long sums(大数加法——某一位的数字可能大于10)

    /*
     * 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, 0, 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("
    ");
    		if (t > 0) {
    			printf("
    ");
    		}
    	}
    	return 0;
    }
    


  • 相关阅读:
    幻灯片效果
    国外空间乱码的解决方法
    图片自动适应
    css圆角效
    iframe自适应兼容
    css圆角
    图片自动适应2
    JQuery实现智能输入提示(仿机票预订网站)
    AppDiag类
    c# 渐变算法
  • 原文地址:https://www.cnblogs.com/pangblog/p/3398140.html
Copyright © 2011-2022 走看看