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.操作期间,进行四则运算时若大整数为正数请 ...
随机推荐
- Print Article hdu 3507 一道斜率优化DP 表示是基础题,但对我来说很难
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- 超级密码 hdu1226 bfs
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- bzoj2330(差分约束)
题解:这道题是练差分约束的一道好题目吧,我具体在代码中注释,这样更加好理解, 为什么求最长路呢?因为这样保证了满足条件,如果存在正权环,就表示无解,就是 正权环之间不断要更多的糖果才行. #inclu ...
- MyBatis 关系映射XML配置
关系映射 在我看来这些实体类就没啥太大关联关系,不就是一个sql语句解决的问题,直接多表查询就完事,程序将它设置关联就好 xml里面配置也是配置了sql语句,下面给出几个关系的小毛驴(xml) 一对多 ...
- Vue 爬坑之路(六)—— 使用 Vuex + axios 发送请求
Vue 原本有一个官方推荐的 ajax 插件 vue-resource,但是自从 Vue 更新到 2.0 之后,官方就不再更新 vue-resource 目前主流的 Vue 项目,都选择 axios ...
- 【转】HTTP Header 详解
HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服务器给与响应.就整个网络资源传 ...
- checkValidity-表达验证方法。
调用该方法,可以显示对表单元素进行有效验证,返回值是boolean. 代码如下: <!DOCTYPE html> <html> <head> <meta ch ...
- ubuntu6.04下安装Eclipse for C/C++ Development
ubuntu6.04下安装Eclipse for C/C++ Development 首先安装gcc/g++ 需要安装jdk,有的可以尝试安装openjdk. sudo apt-get install ...
- Akka(29): Http:Server-Side-Api,Low-Level-Api
Akka-http针对Connection的两头都提供了方便编程的Api,分别是Server-Side-Api和Client-Side-Api.通过这两个Api可以大大提高编程效率.当然,上期我们提到 ...
- PHP中header的作用
1.跳转: //若等待时间为0,则与header("location:")等效. //Header("Location:http://localhost//sessio ...