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.操作期间,进行四则运算时若大整数为正数请 ...
随机推荐
- 读Zepto源码之IOS3模块
IOS3 模块是针对 IOS 的兼容模块,实现了两个常用方法的兼容,这两个方法分别是 trim 和 reduce . 读 Zepto 源码系列文章已经放到了github上,欢迎star: readin ...
- load data(sql)
一般对于数据库表的插入操作,我们都会写程序执行插入sql,插入的数据少还可以,如果数据多了.执行效率上可能就不太理想了.load data语句用于高速地从一个文本文件中读取数据,装载到一个表中,相比于 ...
- 机器学习之numpy库中常用的函数介绍(一)
1. mat() mat()与array的区别: mat是矩阵,数据必须是2维的,是array的子集,包含array的所有特性,所做的运算都是针对矩阵来进行的. array是数组,数据可以是多维的,所 ...
- EnCase missed some usb activities in the evidence files
My friend is a developer and her colleague May was suspected of stealing the source code of an impor ...
- KM算法的应用
HDU2255 模板 难度x HDU2282 思维 难度XXx HDU3722 模板 难度X HDU3395 模版 HDU1533 最小值模型 难度x HDU2853 HDU3 ...
- IDL 使用数组
1.下标方式 IDL> array=indgen(8) IDL> print,array 0 1 2 3 4 5 6 7 IDL> print,array[3] IDL> ar ...
- SAP 动态设置 GUI STATUS 灰色不可用 或者隐藏(转)
http://blog.sina.com.cn/s/blog_66110f6201017rul.html 有时候需要根据用户的权限或者是操作动态设置gui状态上的某些按钮的可用和不可用. 1.先定 ...
- Session详解及集群共享
Session的介绍 维基百科:会话(session)是一种持久网络协议,在用户(或用户代理)端和服务器端之间创建关联,从而起到交换数据包的作用机制,session在网络协议(例如telnet或FTP ...
- mb_substr函数
定义和用法 mb_substr() 截取字符串中指定长度字符 注:常用于中文截取,可以避免截取时候出现乱码,即截取半个字符的情况. 类似函数 substr(),iconv_substr() 语法 mb ...
- eclipse远程调试Linux环境下的web项目
前提: 远程服务器上的代码和本地的代码同步 第一步 : 配置远程服务器下的startup.sh文件 在第一行添加 : declare -x CATALINA_OPTS="-server -X ...