#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm> using namespace std; string bigmun(string a,string b){
    string c;
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    char ans[2000];
    int l=0,plus=0,i;
    char x[2000];
    for(i=0;i<max(a.size(),b.size())-min(a.size(),b.size());i++){
        x[i]='0';
    }
    x[i]='\0';
    string xx=x;
    if(a.size()<b.size()){
        a=a+xx;
    }
    else{
        b=b+xx;
    }
    for(i=0;i<min(a.size(),b.size());i++){
        int x=a[i]-'0';
        int y=b[i]-'0';
        int z=x+y;
        z+=plus;
        plus=0;
        ans[l++]=z%10+'0';
        plus+=z/10;
    }
    if(plus!=0){
        ans[l++]=plus+'0';
    }
    ans[l]='\0';
    c=ans;
    reverse(c.begin(), c.end());
    return c;
} int main(){
    int n;
    scanf("%d",&n);
    int Case;
    Case=1;
    while (n--) {
        string a,b,c;
        cin>>a>>b;
        c=bigmun(a,b);
        printf("Case %d:\n",Case++);
        if(n!=0){
            cout<<a<<" "<<"+"<<" "<<b<<" "<<"="<<" "<<c<<endl;
            cout<<endl;
        }
        else{
            cout<<a<<" "<<"+"<<" "<<b<<" "<<"="<<" "<<c<<endl;
        }
    }
    return 0;
}

大数加法 HDU 1002的更多相关文章

  1. 大数加法~HDU 1002 A + B Problem II

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...

  2. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

  3. hdu 1002 A + B Problem II【大数加法】

    题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...

  4. HDU 1002 A - A + B Problem II (大数问题)

    原题代号:HDU 1002 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 原题描述: Problem Description I have a ...

  5. HDU——1715大菲波数(大数加法)

    大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. A + B Problem II(大数加法)

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Other ...

  7. Hat's Fibonacci(大数加法+直接暴力)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...

  8. ZZNU 2125:A + B 普拉斯(傻逼题+大数加法)

    2125: A + B 普拉斯 时间限制: 1 Sec  内存限制: 128 MB 提交: 94  解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 "别人总说 ...

  9. 51nod 1005 大数加法

    #include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...

随机推荐

  1. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或

    题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...

  2. IOC入门1

    1.配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...

  3. Css的使用细谈

    Css的使用细谈 Css可以通过简单的更改CSS文件,改变网页的整体表现形式,可以减少我们的工作量,所以她是每一个网页设计人员的必修课. Css简介              (1) CSS是用于布局 ...

  4. syslog格式

    转自:http://wly719.iteye.com/blog/1827394 1.syslog格式介绍 在Unix类操作系统上,syslog广泛 应用于系统日志.syslog日志消息既可以记录在本地 ...

  5. dyld: could not load inserted library '/Developer/usr/lib/libBacktraceRecording.dylib' because no suitable image found. Did find:

    错误: dyld: could not load inserted library '/Developer/usr/lib/libBacktraceRecording.dylib' because n ...

  6. 51nod1060:最复杂的数(DFS求反素数)

    把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数.   例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6.如果有多个数复杂度相等,输出最 ...

  7. bzoj 2179 FFT快速傅立叶 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2179 默写板子,注释的是忘记的地方. 代码如下: #include<iostream& ...

  8. 使用svnsync实时备份SVN版本库

    前段时间把SVN版本库从win迁移到了Linux上,没隔几天那台win的磁盘就严重坏道了....这TMD什么运气! 花费了点时间研究了下svn自己的同步工具.写个日志记录下. 注意:svnsync要求 ...

  9. xen添加网卡

    brctl addbr xenbr0 ifconfig xenbr0 up ifconfig xenbr0 192.168.0.1 /etc/xen/scripts/network-bridge st ...

  10. Thief in a Shop

    题意: 问n个物品选出K个可以拼成的体积有哪些. 解法: 多项式裸题,注意到本题中 $A(x)^K$ 的系数会非常大,采用NTT优于FFT. NTT 采用两个 $2^t+1$ 质数,求原根 $g_n$ ...