标签:font get 题目 www. 背景 格式 log put algo
此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置。
题目链接 :https://www.luogu.org/problem/show?pid=1601
无
高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b]
分两行输入a,b<=10^500
输出格式:输出只有一行,代表A+B的值
1 1
2
AC代码:
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 6 using namespace std; 7 const int MAXN = 10000 + 5; 8 9 struct bign 10 { 11 int len; 12 bool flag; 13 int num[MAXN]; 14 15 bign(){len = 0;flag = false;memset(num,0,sizeof(num));} 16 17 void clear() 18 { 19 len = 0; 20 flag = false; 21 memset(num,0,sizeof(num)); 22 } 23 }; 24 bign ans; 25 26 bign operator + (bign &a,bign &b) 27 { 28 ans.clear(); 29 int x = 0; 30 int len = max(a.len,b.len)+1; 31 32 for(int i = 1;i <= len;++ i) 33 { 34 ans.num[i] = a.num[i] + b.num[i] + x; 35 x = ans.num[i]/10; 36 ans.num[i] %= 10; 37 } 38 39 if(!ans.num[len]) len --; 40 ans.len = len; 41 42 return ans; 43 } 44 45 inline bign get() 46 { 47 ans.clear(); 48 string s; 49 cin>>s; 50 int len = s.length(); 51 for(int i = 0;i < len;++ i) 52 ans.num[len-i] = s[i]-‘0‘; 53 ans.len = len; 54 return ans; 55 } 56 57 inline void print(bign a) 58 { 59 int len = a.len; 60 for(int i = len;i >= 1;-- i) 61 printf("%d",a.num[i]); 62 puts(""); 63 } 64 65 int main() 66 { 67 bign a,b; 68 a = get(); 69 b = get(); 70 print(a+b); 71 return 0; 72 }
标签:font get 题目 www. 背景 格式 log put algo
原文地址:http://www.cnblogs.com/shingen/p/7467368.html