• A + B Problem II(1002)


    hdu1002

    题意:大数相加

     
    #include<bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <string.h>
    #include <vector>
    typedef long long ll ;
    #define int ll
    #define mod 1000000007
    #define gcd __gcd
    #define rep(i , j , n) for(int i = j ; i <= n ; i++)
    #define red(i , n , j)  for(int i = n ; i >= j ; i--)
    #define ME(x , y) memset(x , y , sizeof(x))
    //ll lcm(ll a , ll b){return a*b/gcd(a,b);}
    ll quickpow(ll a , ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;b>>=1,a=a*a%mod;}return ans;}
    //int euler1(int x){int ans=x;for(int i=2;i*i<=x;i++)if(x%i==0){ans-=ans/i;while(x%i==0)x/=i;}if(x>1)ans-=ans/x;return ans;}
    //const int N = 1e7+9; int vis[n],prime[n],phi[N];int euler2(int n){ME(vis,true);int len=1;rep(i,2,n){if(vis[i]){prime[len++]=i,phi[i]=i-1;}for(int j=1;j<len&&prime[j]*i<=n;j++){vis[i*prime[j]]=0;if(i%prime[j]==0){phi[i*prime[j]]=phi[i]*prime[j];break;}else{phi[i*prime[j]]=phi[i]*phi[prime[j]];}}}return len}
    #define SC scanf
    #define INF  0x3f3f3f3f
    #define PI acos(-1)
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define size(v) (int)(v.size())
    #define lson l,mid,root<<1
    #define rson mid+1,r,root<<1|1
    using namespace std;
    const int N = 1e6+7;
    const int maxn = 5e2+9;
    int cnt ;
    string plu(string a , string b){//大数加最优版本
        int i , j ; if(size(a) < size(b)) swap(a , b);//a长度更长
        for(i = size(a)-1 , j = size(b)-1 ; i >= 0 ; i-- , j--){//不逆置,直接从后双指针模拟
            a[i] = a[i] + (j >=0 ? b[j] - '0' : 0) ;
            if(a[i]-'0' >= 10){
                a[i] = a[i] - 10 ;
                if(i) a[i-1]++;
                else a = '1' + a ;//答案只可能比a长度长1且为1.
            }
        }
        return a;
    }
    void solve(){
        if(cnt) cout << endl;
        string a , b ;
        cin >> a >> b;
        cout << "Case " << ++cnt << ":" << endl;
        cout << a << " + " << b << " = " << plu(a , b) << endl;
    }
    
    signed main()
    {
        //ios_base::sync_with_stdio(false);
        //cin.tie(NULL);cout.tie(NULL);
        int _ ;cin>>_;while(_--)
            solve();
    }
     
  • 相关阅读:
    CSS学习(五)
    1. Git-2.12.0-64-bit .exe下载
    90.bower解决js的依赖管理
    89.[NodeJS] Express 模板传值对象app.locals、res.locals
    88.NODE.JS加密模块CRYPTO常用方法介绍
    87.node.js操作mongoDB数据库示例分享
    50.AngularJs directive详解及示例代码
    49.AngularJs 指令directive之controller,link,compile
    48.AngularJS ng-src 指令
    86.express里面的app.configure作用
  • 原文地址:https://www.cnblogs.com/nonames/p/11185641.html
Copyright © 2020-2023  润新知