标签:char string mat nbsp 思想 har 整数 class bsp
思想:逢十进一,将大的数字转化为字符串存储。
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn = 1000; int a[maxn]; int b[maxn]; int c[maxn]; char s[maxn]; char t[maxn]; int main(void) { cin>>s; cin>>t; int lens = strlen(s); int lent = strlen(t); for(int i = 0; i < lens; i++) a[lens-i] = s[i]-‘0‘; for(int i = 0; i < lent; i++) b[lent-i] = t[i]-‘0‘; int lenc = 1; int x = 0; while(lenc<=lens||lenc<=lent) { c[lenc] = a[lenc]+b[lenc]+x; x = c[lenc]/10; c[lenc] = c[lenc]%10; lenc++; } c[lenc] = x; while(c[lenc]==0) lenc--; for(int i = lenc; i >= 1; i--) cout<<c[i]; cout<<endl; return 0; }
标签:char string mat nbsp 思想 har 整数 class bsp
原文地址:https://www.cnblogs.com/AC-AC/p/9734784.html