#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int a[1001],b[1001];
char c[1001];
string jj(string a,string b)
{
    int i1 = a.size() - 1;
    int i2 = b.size() - 1;

    string s;
    int carry = 0;
    while (i1 >= 0 || i2 >= 0)
    {
        char ch = carry;
        if (i1 >= 0)
        {
            if (a[i1] < '0' || a[i1] > '9')
                continue;
            ch += a[i1] - '0';
        }
        if (i2 >= 0)
        {
            if (b[i2] < '0' || b[i2] > '9')
                continue;
            ch += b[i2] - '0';
        }
        if (ch >= 10)
        {
            carry = 1;
            ch -= 10;
        }
        else carry = 0;
        s.push_back(ch + '0');
        i1--;
        i2--;
    }
    if (carry) s.push_back('1');
    reverse(s.begin(), s.end());
    return s;
}
class Decimal
{
public:
    string s1;
    Decimal(string a=""):s1(a){}
    Decimal(unsigned long long int n)
    {
    stringstream ss;
    string str;
    ss<<n;
    ss>>str;
    s1=str;
    }
    friend istream &operator >>(istream & it,Decimal &T)
    {
        it>>T.s1;
        return it;
    }
    friend ostream &operator << (ostream & os,const Decimal &T)
    {
        os<<T.s1;
        return os;
    }
    friend Decimal operator + ( Decimal T1,Decimal T2)
    {
    string cs=jj(T1.s1,T2.s1);
    return Decimal(cs);
    }
    Decimal &operator ++()
    {
        string t="1";
        string tt=jj(t,s1);
        s1=tt;
        return *this;
    }
    char operator [](int i)
    {
        return s1[i];
    }
    int getLength()
    {
        return s1.size();
    }
};
int main()
{
    Decimal a, b, c, d, e, f("554433"), g(12345);
    int i;
    cin>>a>>b>>i;
    cout<<"a = "<<a<<endl;
    cout<<"b = "<<b<<endl;
    cout<<"i = "<<i<<endl;
    c = a + b;
    d = ++a;
    e = b + i;
    cout<<"a = "<<a<<endl;
    cout<<"c = "<<c<<endl;
    cout<<"d = "<<d<<endl;
    cout<<"e = "<<e<<endl;
    cout<<"f = "<<f<<endl;
    cout<<"g = "<<g<<endl;

    cout<<c[0];
    for (i = 1; i < c.getLength(); i++)
    {
        cout<<" "<<c[i];
    }
    cout<<endl;
    return 0;
}

  

Problem B: 大整数的加法运算 升级版的更多相关文章

  1. Problem B: 大整数的加法运算

    Problem B: 大整数的加法运算 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 112  Solved: 57[Submit][Status][W ...

  2. 大整数加减运算的C语言实现

    目录 大整数加减运算的C语言实现 一. 问题提出 二. 代码实现 三. 效果验证 大整数加减运算的C语言实现 标签: 大整数加减 C 一. 问题提出 培训老师给出一个题目:用C语言实现一个大整数计算器 ...

  3. 用Java的大整数类BigInteger来实现大整数的一些运算

    关于BigInteger的构造函数,一般会用到两个: BigInteger(String val); //将指定字符串转换为十进制表示形式: BigInteger(String val,int rad ...

  4. RNN入门(4)利用LSTM实现整数加法运算

      本文将介绍LSTM模型在实现整数加法方面的应用.   我们以0-255之间的整数加法为例,生成的结果在0到510之间.为了能利用深度学习模型模拟整数的加法运算,我们需要将输入的两个加数和输出的结果 ...

  5. 1024 Palindromic Number int_string转换 大整数相加

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  6. 基于Java的大整数运算的实现(加法,减法,乘法)学习笔记

    大整数,顾名思义就是特别大的整数. 一台64位的机器最大能表示的数字是2的64次方减一: 18446744073709551615 java语言中所能表示的整数(int)最小为-2147483648 ...

  7. HDU1002——大整数加法

    题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...

  8. A——大整数加法(HDU1002)

    题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...

  9. C语言课程设计大整数运算

    该大整数运算系统用于对有符号的位数不超过500位的大整数进行加.减.乘.除四则运算和计算N(0<=N<=10000)的阶乘.注意事项 :    1.操作期间,进行四则运算时若大整数为正数请 ...

随机推荐

  1. poj1067威佐夫博奕

    取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31490   Accepted: 10374 Descripti ...

  2. poj1006中国剩余定理

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103506   Accepted: 31995 Des ...

  3. redis C接口hiredis 简单函数使用介绍

    hiredis是redis数据库的C接口,目前只能在linux下使用,几个基本的函数就可以操作redis数据库了. 函数原型:redisContext *redisConnect(const char ...

  4. MySQL or MariaDB 错误解决方法之报错代码1045

    phpMyAdmin登录报错:mysqli_real_connect(): (28000/1045): Access denied for user 'root'@'localhost' (using ...

  5. 退出psql时,报psql_history的错

    数据库版本:Enterprisedb 9.2(postgreSQL) 错误如下所示: postgres=# exitcould not save history to file "/opt/ ...

  6. MyEclipse的JQuery.min.js报错红叉解决办法

    MyEclipse的JQuery.min.js报错红叉解决办法 1.选中报错的jquery文件"jquery-1.2.6.min.js".2.右键选择 MyEclipse--> ...

  7. 大概是:整数划分||DP||母函数||递推

    整数划分问题 整数划分是一个经典的问题. Input 每组输入是两个整数n和k.(1 <= n <= 50, 1 <= k <= n) Output 对于每组输入,请输出六行. ...

  8. JS 巧用 && 与 ||

    在对于流程控制语句当中,我们最熟悉不过的就是 if (条件){ //代码块 }else{ //代码块 } 对于一个执行不同的代码来说,如果执行的代码很多,可能就有必要使用上面这种方式 但往往我们开发当 ...

  9. WPF 快捷键读写txt

    因为git提交需要写这次做的,所以我想弄个东西来帮我写 WPF可以使用快捷键,快捷键主要使用InputBindings,WPF读写文件很简单 我每次都要写 第一句标题 之后就是我写的修改 然后加上我名 ...

  10. UVa1595,Symmetry

    这题居然是1A过的.....最近无比失落的心情顿时愉悦起来~ 将数据全部读入 先用二维数据来存储坐标(先把题做出来再说= =) 题目中的x,y的坐标范围是-1W到1W....在数组下标里是不能用负数保 ...