HDU1002

注意大数组声明要放在函数外

#include<iostream>
#include<cstdio>
#include<cstdlib>

using namespace std;

#define MAX_LENGTH 1005
char str_a[MAX_LENGTH],str_b[MAX_LENGTH];
int a[MAX_LENGTH];

int main(){
    int round;
    scanf("%d",&round);
    for(int roundNum=0;roundNum<round;++roundNum){
        bool exchange= false;
//        fflush(stdin);
        scanf(" %s%s",str_a,str_b);
//        printf("a:%s| b:%s|",str_a,str_b);
        memset(a,0, sizeof(a));

        if(strlen(str_a)>strlen(str_b)){
            swap(str_a,str_b);
            exchange = true;
        }
        int len_a=strlen(str_a),len_b=strlen(str_b);
        // b is longer

        int c=0;
        for(int i=0;i<len_a;++i)a[len_a-i-1]=str_a[i]-'0';
        for(int i=0;i<len_b;++i){
            a[i] = a[i]+c+str_b[len_b-i-1]-'0';
            c = a[i]/10;
            a[i] = a[i]%10;
        }
        if(c)a[len_b]=c;

        while(a[len_b]==0&&len_b>0)--len_b;
        if(roundNum>0)printf("\n");
        if(exchange){
            printf("Case %d:\n%s + %s = ", roundNum+1,str_b,str_a);
        }
        else printf("Case %d:\n%s + %s = ", roundNum+1,str_a,str_b);
        while(0<=len_b){
            if(len_b==0){
                printf("%d\n",a[len_b--]);
            }
            else printf("%d",a[len_b--]);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值