题目:http://acm.hdu.edu.cn/showproblem.php?pid=1002
复习一下大数
模板:
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <assert.h> 6 #include <ctype.h> 7 #include <map> 8 #include <string> 9 #include <set> 10 #include <bitset> 11 #include <utility> 12 #include <algorithm> 13 #include <vector> 14 #include <stack> 15 #include <queue> 16 #include <iostream> 17 #include <fstream> 18 #include <list> 19 using namespace std; 20 21 const int MAXL = 1005; 22 struct BigNum 23 { 24 int num[MAXL]; 25 int len; 26 BigNum() 27 { 28 memset(num,0,sizeof(num)); 29 } 30 }; 31 32 //高精度加法 33 BigNum Add(BigNum &a, BigNum &b) 34 { 35 BigNum c; 36 int i, len; 37 len = (a.len > b.len) ? a.len : b.len; 38 memset(c.num, 0, sizeof(c.num)); 39 for(i = 0; i < len; i++) 40 { 41 c.num[i] += (a.num[i]+b.num[i]); 42 if(c.num[i] >= 10) 43 { 44 c.num[i+1]++; 45 c.num[i] -= 10; 46 } 47 } 48 if(c.num[len]) 49 len++; 50 c.len = len; 51 return c; 52 } 53 void print(BigNum &a) //输出大数 54 { 55 int i; 56 for(i = a.len-1; i >= 0; i--) 57 printf("%d", a.num[i]); 58 printf(" "); 59 } 60 61 62 void Init(BigNum &a, char *s, int &tag) //将字符串转化为大数 63 { 64 int i = 0, j = strlen(s); 65 if(s[0] == '-') 66 { 67 j--; 68 i++; 69 tag *= -1; 70 } 71 a.len = j; 72 for(; s[i] != '