问题描述

输入两个数求余和求模的结果

思路

套用大数模板。。

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=1000;
struct bign
{int len,s[maxn];bign(){memset(s,0,sizeof(s));len=1;}bign(int num){*this=num;}bign(const char *num){*this=num;}bign operator = (const int num){char s[maxn];sprintf(s,"%d",num);*this=s;return *this;}bign operator = (const char *num){len=strlen(num);for(int i=0;i<len;i++)s[i]=num[len-i-1]-'0';return *this;}//输出string str() const{string res="";for(int i=0;i<len;i++){res=(char)(s[i]+'0')+res;}if(res=="")res="0";return res;}void clean(){while(len>1&&!s[len-1])len--;}bign operator + (const bign &b) const{bign c;c.len=0;for(int i=0,g=0;g||i<max(len,b.len);i++){int x=g;if(i<len) x+=s[i];if(i<b.len) x+=b.s[i];c.s[c.len++]=x%10;g=x/10;}return c;}bign operator - (const bign& b) const{bign c;c.len=0;for(int i=0,g=0;i<len;i++){int x=s[i]-g;if(i<b.len) x-=b.s[i];if(x>=0)g=0;else{g=1;x+=10;}c.s[c.len++]=x;}c.clean();return c;}bign operator * (const bign& b) const{bign c;c.len=len+b.len;for(int i=0;i<len;i++){for(int j=0;j<b.len;j++)c.s[i+j]+=s[i]*b.s[j];}for(int i=0;i<c.len-1;i++){c.s[i+1]+=c.s[i]/10;c.s[i]%=10;}c.clean();return c;}bign operator / (const bign &b)const{bign ret,cur=0;ret.len=len;for(int i=len-1;i>=0;i--){cur=cur*10;cur.s[0]=s[i];while(cur>=b){cur-=b;ret.s[i]++;}}ret.clean();return ret;}bign operator %(const bign &b) const{bign c=*this/b;return *this-c*b;}bool operator <(const bign& b) const{if(len!=b.len) return len<b.len;for(int i=len-1;i>=0;i--)if(s[i]!=b.s[i])return s[i]<b.s[i];return false;}bool operator >(const bign& b) const{return b < *this;}bool operator <=(const bign& b) const{return !(b < *this);}bool operator >=(const bign& b) const{return !(*this <b);}bool operator ==(const bign& b) const{return !(b< *this)&&!(*this<b);}bool operator !=(const bign& b) const{return *this >b || *this <b;}bign operator +=(const bign& b){*this= *this + b;return *this;}bign operator -=(const bign& b){*this= *this - b;return *this;}bign operator *=(const bign& b){*this= *this * b;return *this;}bign operator /=(const bign& b){*this= *this / b;return *this;}bign operator %=(const bign& b){*this= *this % b;return *this;}
};istream& operator >> (istream &in, bign& x)
{string s;in >> s;x = s.c_str();return in;
}ostream& operator << (ostream &out, const bign& x)
{out << x.str();return out;
}int main()
{bign a,b;string s;while(cin>>a>>s>>b){a.clean();   //考虑清除前导0b.clean();if(s=="/")cout<<a/b<<endl;elsecout<<a%b<<endl;}return 0;
}

UVA10494 - If We Were a Child Again相关推荐

  1. UVA10494 If We Were a Child Again【大数除法】

    "Oooooooooooooooh!     If I could do the easy mathematics like my school days!!     I can guara ...

  2. 题目梳理(一)(2019.07.06~2019.07.20)

    一.字典树类型 A   HihoCoder1014 Trie树(已做) 题目链接    https://hihocoder.com/problemset/problem/1014 B    HDU12 ...

  3. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  4. oracle 提示:ORA-02292:integrity constraint(xxxxxxx) violated - child record found

    当我们删除 数据的时候 oracle 提示:ORA-02292:integrity constraint(xxxxxxx) violated - child record found 这种情况呢是因为 ...

  5. CF438E The Child and Binary Tree(有意思的生成函数 + 多项式求逆 + 多项式开方)

    整理的算法模板合集: ACM模板 点我看多项式全家桶(●^◡_◡◡​^●) CF438E The Child and Binary Tree 简单的黑题 首先我们发现模数为99824435399824 ...

  6. 存在就不插入_DOM 插入节点和三个Child方法

    插入节点 insertBefor(); 插入格式:父节点.insertBefor( 插入节点,旧节点 )功能:将插入的节点插入到旧节点之前举个小例子:创建一个strong节点,将这个节点插入到span ...

  7. [翻译]AKKA笔记 - CHILD ACTORS与ACTORPATH -6

    原文:http://rerun.me/2014/10/21/akka-notes-child-actors-and-path/ Actor是完全的继承结构.你创建的任何Actor肯定都是一个其他Act ...

  8. 【转】Silverlight 3 Beta 新特性解析(7)- Child Window和Shader Effect篇

    前提条件: 阅读本文之前请确认你已经安装了如下软件 Visual Studio 2008 (Express) SP1 Silverlight 3 Tools For Visual Studio Mic ...

  9. mongodb启动不了:child process failed, exited with err

    2019独角兽企业重金招聘Python工程师标准>>> [摘要:本日正在设置装备摆设mongodb时产生了以下几个毛病, 已被我办理了,供应给人人. 2015-05-12T09:30 ...

最新文章

  1. 【Qt】QCloseEvent的使用小结
  2. 云服务收入年增长28%
  3. Spring Cloud系列:不重启eureka,清除down掉的服务
  4. 【slighttpd】基于lighttpd架构的Server项目实战(8)—状态机机制回顾
  5. 三级菜单页面布局_三级菜单的最快导航布局
  6. sklearn集合算法预测泰坦尼克号幸存者
  7. RGB转YUV420
  8. iPhone开发笔记[1/50]:初学iPhone上用Quartz 2D画图
  9. chrome扩展之4(终结篇):一步步跟我学开发一个表单填写扩展
  10. Tensorflow保存神经网络参数有妙招:Saver和Restore
  11. 怎么让打印出来表格的纸下面显示页数_4个使用频率较高的Excel打印技巧,办公室打印文件时常常会用到!...
  12. C语言137页答案,综合化学实验答案题库(137页)-原创力文档
  13. 【Antlr】WHITESPACE is not a recognized channel name
  14. Android Native Hook工具
  15. (结构型模式)FlyWeight——享元模式
  16. IsPostBack结论
  17. 暴力破解QQ空间设置的问题
  18. python在abaqus中的应用pdf_Python语言在Abaqus中的应用
  19. React-router 嵌套路由传值(render和children)
  20. 数学建模写作时相关的套路

热门文章

  1. 365天挑战LeetCode1000题——Day 120 基于时间的最大报酬问题模板
  2. C#托管代码和非托管代码的区别
  3. 江南十日行(一)杭州(上)
  4. 奥里给,干了兄弟们。
  5. 142、解密POE交换机供电秘密,8芯网线断芯不再害怕!
  6. centos上通过ll或者du命令查看文件的大小
  7. 导航上显示某个地点已关闭什么意思_你的手机地图APP只用来导航?这些隐藏功能不用就太可惜了!...
  8. python如何录音_python实现录音功能
  9. 【帆软报表】报表类型简介
  10. 网站关键词的选择和优化设置技巧