提交时间:2023-08-02 22:04:09
运行 ID: 24016
#include<bits/stdc++.h> using namespace std; struct bign { int d[1000]; int len; bign() { len = 0; memset(d,0,sizeof(d)); } }; bign change(char str[]) { bign a; int len=strlen(str); for(int i=0;i<strlen(str);i++){ a.d[a.len]=str[len-i-1]-'0'; a.len++; } return a; } void print(bign a){ for(int i=a.len-1;i>=0;i--){ cout<<a.d[i]; } } bign add(bign a,bign b) { bign c; int carry=0; for(int i=0;i<a.len||i<b.len;i++){ int temp=a.d[i]+b.d[i]+carry; c.d[i]=temp%10; c.len++; carry=temp/10; } if(carry>0){ c.d[c.len]=carry; c.len++; } while(c.d[c.len-1]==0&&c.len>1){ c.len--; } return c; } int main() { char s1[100],s2[100]; cin>>s1; cin>>s2; bign a=change(s1); bign b=change(s2); print(add(a,b)); return 0; }