前言 这两天在刷算法题,其中涉及到了高精度算法,由于笔者使用C++,所以需要手动去模拟实现。使用java和python的同学可以不用担心,Java有BigDecimal类可以实现,python可以直接实现。 好了下面我们直接上代码,代码都有相应的注释,相信可以看懂的。 代码 更多内容大家可以访问我的 ...
分类:
编程语言 时间:
2020-03-12 12:44:18
阅读次数:
58
1 #include 2 #include 3 #include 4 using namespace std; 5 char s1[10005],s2[10005]; 6 int a[10005],b[10005],c[10005]; 7 int flag; 8 int main() 9 { 10 ... ...
分类:
其他好文 时间:
2018-11-03 00:04:21
阅读次数:
110
计算机处理的各种数据类型都有个范围,超出范围的就处理不了。 如果做超大数运算加减乘除,普通方法肯定是不行的,那么我们遇到大数的运算怎么处理呢?今天介绍一种大数加减乘除运算的方法 思路: 1. 将两个特大的整数利用字符数组作为存储介质。 2. 逐位计算 遍历结果逢十进一。 3. 对存储结果的数组进行翻 ...
分类:
编程语言 时间:
2018-04-01 13:19:40
阅读次数:
179
1 #include 2 #include 3 using namespace std; 4 #define MAX 10005 5 6 struct bigint 7 { 8 char num[MAX]; 9 int flag; // 1:positive -1:negative 10 int d... ...
分类:
其他好文 时间:
2017-05-01 12:51:01
阅读次数:
142
写了5个小时,C++面向对象的东西都不会写了。。。以后要多写C++少写python。。。关于读入字符串处理的那部分写得太挫就不放了。 #include "List.hpp" 1 #pragma once 2 #include <cstdio> 3 #include <cassert> 4 5 nam ...
分类:
其他好文 时间:
2016-05-09 21:58:46
阅读次数:
247
Description Jiajia and Wind have a very cute daughter called Autumn. She is so clever that she can do integer additions when she was just 2 years old!
分类:
其他好文 时间:
2016-01-28 19:20:26
阅读次数:
251
#define _CRT_SECURE_NO_WARNINGS
#include
#define MAXSIZE 10
void Add(char a[], char b[], char c[]);
void Sub(char a[], char b[], char c[]);
int Get_len(char a[]);
bool Max_a(char a[], char b[]);...
分类:
编程语言 时间:
2015-04-18 20:39:25
阅读次数:
228
大数加法
char* MaxAdd(char *str1,char *str2){
int len1=strlen(str1);
int len2=strlen(str2);
int num1[MAX]={0};
int num2[MAX]={0};
for(int j=0,i=len1-1;i>=0;i--,j++){
num1[j]=str1[i]-'0'; //转换为int数...
分类:
其他好文 时间:
2015-04-15 13:39:29
阅读次数:
153
传送门 1 /* 2 * input: an expression seperated by a '-' or '+'; for example: a-b, a+b 3 * ouput: the answer of the input expression 4 */ 5 #includ...
分类:
其他好文 时间:
2015-01-14 15:29:19
阅读次数:
125
本题题目没明确说明有多大的数,主要是A, B < 32768迷惑人,好像不是大数,不过后面 The size of input will not exceed 50K 的这句话就说明是大数了可以为接近无穷大的负数。
其实50K就应该开多大的数组呢?50 * 1024 / 8 == 6400,所以会有6400个数位。
这里直接使用C++的vector或者string,然后输入使用buffer,那么就可以不管数位有多大了。
大数加法比较容易,如果是减法那么题目就比较麻烦了。目前还想不到比较简洁的解法,要特殊处理...
分类:
其他好文 时间:
2014-10-25 08:11:47
阅读次数:
283