#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. "makefile:5: *** missing separator. Stop."【转】

    本文转载自:http://blog.csdn.net/fireroll/article/details/8607903 写makefile时出现这个错误提示 是表示makefile中的命令前没有使用T ...

  2. js程序开发-3

    <h1>Date()类型</h1> 获取日期和时间 getDate() 获取日 1-31 getDay () 获取星期 0-6 getMonth () 获取月 0-11 get ...

  3. uva 401 Palindromes 解题报告

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. PHP 中$_SERVER的用法

    php编程中经常需要用到一些服务器的一些资料,我把常用的用高亮的方式贴出来,其余的放在后面.方便以后查阅$_SERVER['HTTP_ACCEPT_LANGUAGE']//浏览器语言 $_SERVER ...

  5. C和C++语言&

    #include "stdafx.h"#include "iostream"#include "animal.h"using namespa ...

  6. TCP/IP 协议 —— ARP

    通过 ARP 广播获得对方的 MAC 地址: 地址解析协议,即ARP(Address Resolution Protocol),是根据IP地址获取物理地址的一个TCP/IP协议. 1. 特点 ARP ...

  7. shell之cut和tr 的命令的使用

    [root@data-1-3 ~]# head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin ...

  8. 解决在IE11浏览器上,css样式不起作用的问题

    1.首先下载http://pan.baidu.com/s/1c1DA1Ew并运行; 2.在列表中找到.css双击出现Edit File Type; 3.将MIME Type中改为text/css,点击 ...

  9. force

    题意 求解 Ei = Fi/qi 解法: 方法一: 考虑左侧的式子,直接多项式乘法. 对于右面的式子,我们记做$B_j$,这样有 $$B_j = \sum_{j<i}{ revq_{n-i} f ...

  10. Asset Catalog Help (五)---Migrating an iOS App Icon Set or Launch Image Set

    Migrating an iOS App Icon Set or Launch Image Set Simplify image management by moving existing app i ...