Problem B: 大整数的加法运算 升级版
#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: 大整数的加法运算 升级版的更多相关文章
- Problem B: 大整数的加法运算
Problem B: 大整数的加法运算 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 112 Solved: 57[Submit][Status][W ...
- 大整数加减运算的C语言实现
目录 大整数加减运算的C语言实现 一. 问题提出 二. 代码实现 三. 效果验证 大整数加减运算的C语言实现 标签: 大整数加减 C 一. 问题提出 培训老师给出一个题目:用C语言实现一个大整数计算器 ...
- 用Java的大整数类BigInteger来实现大整数的一些运算
关于BigInteger的构造函数,一般会用到两个: BigInteger(String val); //将指定字符串转换为十进制表示形式: BigInteger(String val,int rad ...
- RNN入门(4)利用LSTM实现整数加法运算
本文将介绍LSTM模型在实现整数加法方面的应用. 我们以0-255之间的整数加法为例,生成的结果在0到510之间.为了能利用深度学习模型模拟整数的加法运算,我们需要将输入的两个加数和输出的结果 ...
- 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 ...
- 基于Java的大整数运算的实现(加法,减法,乘法)学习笔记
大整数,顾名思义就是特别大的整数. 一台64位的机器最大能表示的数字是2的64次方减一: 18446744073709551615 java语言中所能表示的整数(int)最小为-2147483648 ...
- HDU1002——大整数加法
题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...
- A——大整数加法(HDU1002)
题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...
- C语言课程设计大整数运算
该大整数运算系统用于对有符号的位数不超过500位的大整数进行加.减.乘.除四则运算和计算N(0<=N<=10000)的阶乘.注意事项 : 1.操作期间,进行四则运算时若大整数为正数请 ...
随机推荐
- kbhit()
kbhit() 非阻塞的响应键盘输入时间 C++函数 功能和返回值:检查是否有键盘输入 ,有返回非0 ,无返回0 int khbit(void) 头文件: #include<conio.h& ...
- centos 6.5系统下安装ibus及设置开机自启动
先说一下系统环境:centos 6.5,然后我是以root身份执行的,没有权限的用户参见sudo用法 第1步:查找并安装ibus安装包,命令如下: 找到一行: ibus-pinyin.x86_64 : ...
- Chinese Rings hdu 2842 矩阵快速幂
Chinese Rings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 在CentOS 7 上安装docker
Docker CE Install yum-utils, which provides the yum-config-manager utility: $ sudo yum install -y yu ...
- 机器学习理论提升方法AdaBoost算法第一卷
AdaBoost算法内容来自<统计学习与方法>李航,<机器学习>周志华,以及<机器学习实战>Peter HarringTon,相互学习,不足之处请大家多多指教! 提 ...
- 将本地代码上传到github
准备工作上传本地代码到github 准备工作 在github上创建自己的Repository. 安装git,centos的git安装教程. 上传本地代码到github git init git add ...
- java 虚拟机与并发处理几个问题简要(二)
六.两个重要的概念性问题: 1.同步:要保持数据的一致性,就需要一种保证并发进程正确执行顺序的机制.这种机制就是 进程同步(Process Synchronization). 竞争资源的多个进程按着特 ...
- WPF控件 在XP下获得焦点有虚线框
所有 Button.ListBox等控件获得焦点时有虚线框.如图:选中523这个按钮就出线虚框. 我在App.xaml中添加适应所有按钮的样式,无效 <Style TargetType=&qu ...
- EasyUI Tree 树 ——实现多级别菜单的展示,以及与后台数据的交互
一 要引入的js css库 <link type="text/css" href="css/base.css" rel="stylesheet& ...
- win10 uwp 俄罗斯方块
俄罗斯方块是一个很经典的游戏,做一个UWP俄罗斯方块没有什么用,我想说的是移植,把经典游戏移植到UWP. 我的所有博客都是抄别人的,这个才是我自己写的.后台很多代码还是抄别人的,我想说的是我们之前有很 ...