http://codevs.cn/problem/3115/

板子题~

// <H.cpp> - Sun Oct  9 12:58:23 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=;
const int MAXM=;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
const int _bod_=;
struct BN{
static const int N=;int a[N];char s[N];
int& operator [](int n){return a[n];}
bool operator <(BN b) const{
if(a[]<b[])return ;
if(a[]>b[])return ;
for(int i=a[];i>=;i--){
if(a[i]>b[i])return ;
if(a[i]<b[i])return ;
}
return ;
}
BN operator -(BN b) const{
BN ans=*this;int q=;
if(ans<b)swap(ans,b),q=-;
for(int i=;i<=ans[];i++){
ans[i]=ans[i]-b[i];
if(ans[i]<){ans[i+]--;ans[i]+=_bod_;}
}
while(ans[]&&!ans[ans[]])ans[]--;
for(int i=;i<=ans[];i++)ans[i]*=q;
return ans;
}
void read(){
scanf("%s",s);a[]=strlen(s);
for(int i=;i<=a[];i++)a[i]=s[a[]-i]-'';
}
void pri(){printf("%d",a[a[]]);for(int i=a[]-;i>=;i--)printf("%.1d",a[i]);}
}a,b;
int main()
{
freopen("3115.in","r",stdin);
freopen("3115.out","w",stdout);
a.read(),b.read();
if(a<b)printf("-"),(b-a).pri();else (a-b).pri();
return ;
}

【Codevs 3115】高精度练习之减法的更多相关文章

  1. wiki oi 3115高精度练习之减法

    题目描述 Description 给出两个正整数A和B,计算A-B的值.保证A和B的位数不超过500位. 输入描述 Input Description 读入两个用空格隔开的正整数 输出描述 Outpu ...

  2. codevs 3119 高精度练习之大整数开根 (各种高精+压位)

    /* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...

  3. codevs 3054 高精度练习-文件操作

    时间限制: 1 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond 题目描述 Description 输入一组数据,将每个数据加1后输出 输入描述 Input Descripti ...

  4. codevs 3123 高精度练习之超大整数乘法

    fft. #include<iostream> #include<cstdio> #include<cstring> #include<complex> ...

  5. codevs 4165 ​高精度求阶乘

    时间限制: 1 s  空间限制: 256000 KB  题目等级 : 白银 Silver 题目描述 Description 用高精度计算出S=n! 其中"!"表示阶乘,例如:5!= ...

  6. c++ 普通高精减

    //c++ 普通高精减 //codevs 3115 高精度练习之减法 //内容简单,就不注释了. //注意下,&&优先级高于||. #include<cstdio>#inc ...

  7. 高精度 - SGU 112 a^b-b^a

    a^b-b^a Problem's Link Mean: 略 analyse: 简单题,只用编个高精度乘法和减法即可. Time complexity: O(N) view code  java im ...

  8. 【目录】洛谷|CODEVS题解汇总

    [动规]爱与愁的心痛 [动规]编辑距离 [动规]采药 [动规]创意吃鱼法 [动规]过河卒 [动规]开心的金明 [动规]旅行 [动规]骑士游历 [动规]数字三角形 [动规]最长连号 [动规]装箱问题 [ ...

  9. 51Nod 1005 有负数的高精度加法

    51Nod是个好地方啊 题意 51Nod基础题第二题,高精度加法,可能有负数. 解题 如果按照一般的高精度,我们发现要分情况讨论,还要写高精度加法和减法,代码实现有点烦.而初中数学里说,省略加号的和. ...

随机推荐

  1. socketserver模块使用方法

    一.socketserver模块介绍 Python提供了两个基本的socket模块.一个是socket,它提供了标准的BSD Socket API: 另一个是socketserver,它提供了服务器中 ...

  2. 杭电 5053 the Sum of Cube(求区间内的立方和)打表法

    Description A range is given, the begin and the end are both integers. You should sum the cube of al ...

  3. Python使用selenium实现网页用户名 密码 验证码自动登录功能

    一.安装selenium 二.下载谷歌浏览器驱动 1.去http://chromedriver.storage.googleapis.com/index.html下载chromedriver.exe( ...

  4. loadrunner-3个难点

    1.loadrunner 监控windows资源 2.loadrunner如何实现如下: 1.1.1.1 场景一 10进程同时新增用户 测试场景说明:10进程新增用户, 第一个进程从1到1000,第二 ...

  5. HDU-2817,同余定理+快速幂取模,水过~

    A sequence of numbers                                                             Time Limit: 2000/1 ...

  6. hihoCoder#1114 小Hi小Ho的惊天大作战:扫雷·一

    原题地址 回溯+搜索 枚举每个位置上能否放地雷,当第i个位置枚举完成后,第i-1个位置的情况就确定了,此时,检查第i-1个位置是否满足要求,即左右间隔为1的范围内地雷数是否等于申明数字,如果满足条件, ...

  7. HDU 4960 (水dp)

    Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. Th ...

  8. Codeforces Round #261 (Div. 2) E (DP)

    E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do hi ...

  9. Ubuntu 16.04 LTS GNOME版本下载

    下载地址: http://cdimage.ubuntu.com/ubuntu-gnome/releases/ Ubuntu GNOME发行版本启动已经有三年的时间了,在社区用户对于在稳定可靠的Ubun ...

  10. Bug记载2之Vue.JS路由定义的位置

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...