题目链接:http://acm.xidian.edu.cn/problem.php?id=1046

题目描述

请输出两个数的和,差,积,商,取余。注意不要有前导零。

输入

多组数据,每组数据是两个整数A,B(0<=A<=10^100,0<B<=10^100).

输出

对于每组数据,输出五个整数,分别代表A+B,A-B,A*B,A/B,A%B.

样例输入
5 2
11 3

样例输出
7 3 10 2 1
14 8 33 3 2

模板注释:

本模板只能处理十进制非负大整数。

AC代码:

#include<bits/stdc++.h>
using namespace std; struct BigInt
{
int len,d[]; void clean(){while(len> && !d[len-]) len--;}
string str()const
{
string s;
for(int i=;i<len;i++) s+=d[len--i]+'';
return s;
} BigInt(){memset(d,,sizeof(d));len=;}
BigInt(int num){*this=num;}
BigInt(char* num){*this=num;} bool operator<(const BigInt& oth)const
{
if(len!=oth.len) return len<oth.len;
for(int i=len-;i>=;i--) if(d[i]!=oth.d[i]) return d[i]<oth.d[i];
return false;
}
bool operator>(const BigInt& oth)const{return oth<*this;}
bool operator<=(const BigInt& oth)const{return !(oth<*this);}
bool operator>=(const BigInt& oth)const{return !(*this<oth);}
bool operator!=(const BigInt& oth)const{return oth<*this || *this<oth;}
bool operator==(const BigInt& oth)const{return !(oth<*this) && !(*this<oth);} BigInt operator=(const char* num)
{
memset(d,,sizeof(d));
len=strlen(num);
for(int i=;i<len;i++) d[i]=num[len--i]-'';
clean();
return *this;
}
BigInt operator=(int num)
{
char s[];
sprintf(s,"%d",num);
return *this=s;
}
BigInt operator+(const BigInt& oth)const
{
BigInt c;
c.len=max(len,oth.len);
for(int i=;i<=c.len;i++) c.d[i]=;
for(int i=;i<c.len;i++)
{
c.d[i]+=(i<len?d[i]:)+(i<oth.len?oth.d[i]:);
c.d[i+]+=c.d[i]/;
c.d[i]%=;
}
c.len+=(c.d[c.len]>);
c.clean();
return c;
}
BigInt operator-(const BigInt& oth)const
{
BigInt c=*this;
if(c<oth) printf("Produce negative number!\n");
int i;
for(i=;i<oth.len;i++)
{
c.d[i]-=oth.d[i];
if(c.d[i]<) c.d[i]+=, c.d[i+]--;
}
while(c.d[i]<) c.d[i++]+=, c.d[i]--;
c.clean();
return c;
}
BigInt operator*(const BigInt& oth)const
{
BigInt c;
for(int i=;i<len;i++) for(int j=;j<oth.len;j++) c.d[i+j]+=d[i]*oth.d[j];
for(int i=;i<len+oth.len || !c.d[i];c.len=++i) c.d[i+]+=c.d[i]/, c.d[i]%=;
c.clean();
return c;
}
BigInt operator/(const BigInt& oth)const
{
BigInt c=*this, r=;
for(int i=;i<len;i++)
{
r=r*+c.d[len--i];
int j;
for(j=;j<;j++) if(r<oth*(j+)) break;
c.d[len--i]=j;
r=r-oth*j;
}
c.clean();
return c;
}
BigInt operator%(const BigInt& oth)
{
BigInt r=;
for(int i=;i<len;i++)
{
r=r*+d[len--i];
int j;
for(j=;j<;j++) if(r<oth*(j+)) break;
r=r-oth*j;
}
return r;
}
BigInt operator+=(const BigInt& oth)
{
*this=*this+oth;
return *this;
}
BigInt operator*=(const BigInt& oth)
{
*this=*this*oth;
return *this;
}
BigInt operator-=(const BigInt& oth)
{
*this=*this-oth;
return *this;
}
BigInt operator/=(const BigInt& oth)
{
*this=*this/oth;
return *this;
}
};
istream& operator>>(istream& in, BigInt& x)
{
string s;
in>>s;
x=s.c_str();
return in;
}
ostream& operator<<(ostream& out,const BigInt& x)
{
out<<x.str();
return out;
} int main()
{
BigInt a,b;
while(cin>>a>>b)
{
cout<<a+b<<" ";
if(a<b) cout<<'-'<<b-a<<" ";
else cout<<a-b<<" ";
cout<<a*b<<" ";
cout<<a/b<<" ";
cout<<a%b<<endl;
}
}

XDOJ 1046 - 高精度模板综合测试 - [高精度模板]的更多相关文章

  1. Django(4)html模板继承、模板导入、分页实现

    1.获取所有请求信息 导入模块:from django.core.handlers.wsgi import WSGIRequest request.environ:包含所有的请求信息,可以打印看一下, ...

  2. [Reprint] C++函数模板与类模板实例解析

    这篇文章主要介绍了C++函数模板与类模板,需要的朋友可以参考下   本文针对C++函数模板与类模板进行了较为详尽的实例解析,有助于帮助读者加深对C++函数模板与类模板的理解.具体内容如下: 泛型编程( ...

  3. C++ Primer 学习笔记_76_模板与泛型编程 --模板定义[续]

    模板与泛型编程 --模板定义[续] 四.模板类型形參 类型形參由keywordclass或 typename后接说明符构成.在模板形參表中,这两个keyword具有同样的含义,都指出后面所接的名字表示 ...

  4. 织梦CMS(dedecms)栏目属性及系统封面模板、列表模板、文章模板区别和路径设置解答

    问题一:(织梦"栏目管理"的"常规选项"中3个栏目属性分析?) 织梦CMS的栏目属性分成三种, -->最终列表栏目 -->频道封面 -->外部 ...

  5. (转)DEDECMS模板原理、模板标签学习 - .Little Hann

    本文,小瀚想和大家一起来学习一下DEDECMS中目前所使用的模板技术的原理: 什么是编译式模板.解释式模板,它们的区别是什么? 模板标签有哪些种类,它们的区别是什么,都应用在哪些场景? 学习模板的机制 ...

  6. C++ Primer 学习笔记_84_模板与泛型编程 --模板特化

    模板与泛型编程 --模板特化 引言: 我们并不总是能够写出对全部可能被实例化的类型都最合适的模板.某些情况下,通用模板定义对于某个类型可能是全然错误的,通用模板定义或许不能编译或者做错误的事情;另外一 ...

  7. Django模板-分离的模板

    上一篇Django模板-在视图中使用模板最后的问题,我们需要把数据和展现分离开. 你可能首先考虑把模板保存在文件系统的某个位置并用 Python 内建的文件操作函数来读取文件内容. 假设文件保存在 E ...

  8. C++ Primer 学习笔记_85_模板与泛型编程 --模板特化[续]

    模板与泛型编程 --模板特化[续] 三.特化成员而不特化类 除了特化整个模板之外,还能够仅仅特化push和pop成员.我们将特化push成员以复制字符数组,而且特化pop成员以释放该副本使用的内存: ...

  9. C++ Primer 学习笔记_75_模板与泛型编程 --模板定义

    模板与泛型编程 --模板定义 引言: 所谓泛型程序就是以独立于不论什么特定类型的方式编写代码.使用泛型程序时,我们须要提供详细程序实例所操作的类型或值. 模板是泛型编程的基础.使用模板时能够无须了解模 ...

随机推荐

  1. Redis server went away的解决方案

    Redis server went away出现的问题如下: 1.看redis服务是否启动,包括端口 2.看是否是服务器端的防火墙引起的,iptables和selinux 3.看是否是redis.co ...

  2. 初始cfx开发webservice, 简单实例应用

    项目结构图: 步骤一: 添加maven 依赖包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...

  3. CSS3 选择器 基本选择器介绍

    CSS是一种用于屏幕上渲染html,xml等一种语言,CSS主要是在相应的元素中应用样式,来渲染相对应用的元素,那么这样我们选择相应的元素就很重要了,如何选择对应的元素,此时就需要我们所说的选择器.选 ...

  4. mysql 编译安装 window篇

    传送门 # mysql下载地址 https://www.mysql.com/downloads/ # 找到MySQL Community Edition (GPL) https://dev.mysql ...

  5. Git教程学习(四)

    12. 分支管理场景 多人协同工作时,你在优化代码X,需要较长时间才能完成,未完成之前会影响整体代码的使用.于是写完的代码不能提交到版本库,提交就会影响别人使用整体的代码.不提交你就失去了git的版本 ...

  6. 2.5 Apache Axis2 快速学习手册之JiBx 构建Web Service

    5. 使用JiBX生成服务(通过JIBX 命令将wsdl 生成 services ) 要使用JiBX数据绑定生成和部署服务,请执行以下步骤. 通过在Axis2_HOME / samples / qui ...

  7. maven dependencies

    http://maven.apache.org/guides/getting-started/index.html https://maven.apache.org/guides/introducti ...

  8. 【Spark深入学习-11】Spark基本概念和运行模式

    ----本节内容------- 1.大数据基础 1.1大数据平台基本框架 1.2学习大数据的基础 1.3学习Spark的Hadoop基础 2.Hadoop生态基本介绍 2.1Hadoop生态组件介绍 ...

  9. “RESOURCE MONITOR“CPU占用特别高

    背景: SQL Server 2008 R2 10.50.1600 没有设置页面文件,内存为64G,数据库分配50G cpu使用占了50%以上,平时只有10-20%,某台服务器“RESOURCE MO ...

  10. Loadrunner C/S关联函数(LSP)AND(LSSS)使用-案例

    LSP就是lrs_save_param()函数 LSSS就是lrs_save_searched_string()函数 一下我们用一个例子去说明他们的使用. C/S机制和B/S不一样,特别是有一个dat ...