zoukankan      html  css  js  c++  java
  • 算法练习(一)(HDU1002 A+B Problem Ⅱ 大数运算)

    HDU1002 A+B Problem Ⅱ 

    https://vjudge.net/contest/310259#problem/B

    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <iostream>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    int main()
    {
    	char chr1[1010],chr2[1010];
    	int t;
    	int len1,len2,len;
    	cin>>t;
        for(int s=1;s<=t;s++){
        	if(s!=1) cout<<endl;
    		int i,j=0,k=0;
    		scanf("%s %s",chr1,chr2);
    		int a[1010]={0},b[1010]={0},c[1010]={0};
    		len1=strlen(chr1);
    		len2=strlen(chr2);
    		for(i=len1-1,j=0;i>=0;i--) a[j++]=chr1[i]-'0';
    		for(i=len2-1,k=0;i>=0;i--) b[k++]=chr2[i]-'0';
    		if(len1>len2) len=len1;
    		else len=len2;
    		int m=0;
    		for(i=0;i<len;i++)
    		{
    		   int temp=a[i]+b[i]+m;
    		   c[i]=temp%10;
    		   m=temp/10;
    		}
    		if(a[i-1]+b[i-1]>=10) c[i]=1;
    		else {
    			c[i]=0;
    			i--;
    		}
    		printf("Case %d:
    ",s);
    		printf("%s + %s = ",chr1,chr2);
    		for(;i>=0;i--) cout<<c[i];
    		cout<<endl;
    	}
    	return 0;
     }  
    天晴了,起飞吧
  • 相关阅读:
    前端面试题
    js collection
    javascript变量声明提升(hoisting)
    css3动画
    神奇的meta
    wap站bug小结
    前端collection
    js拾遗
    prototype之初印象
    自定义scrollBottom的值
  • 原文地址:https://www.cnblogs.com/jianqiao123/p/12075781.html
Copyright © 2011-2022 走看看