#include<iostream>#include<string>#include<algorithm>usingnamespace std;intmain(){
string a, b;int i =0, j;int f =0;//是否产生进位int ans[510];
cin >> a >> b;reverse(a.begin(), a.end());reverse(b.begin(), b.end());
string temp;//保证大数a的长度>=b的长度if(a.length()< b.length()){
temp = a;
a = b;
b = temp;}for(i =0; i < b.length(); i++){
int temp =(a[i]-'0')+(b[i]-'0')+ f;
ans[i]= temp %10;if(temp >=10){
f =1;}else{
f =0;}}if(a.length()> b.length()){
while(i < a.length()){
int temp =(a[i]-'0')+ f;
ans[i]= temp %10;if(temp >=10){
f =1;}else{
f =0;}
i++;}}if(f ==1){
cout << f;}for(j = i -1; j >=0; j--){
cout << ans[j];}return0;}
减法
#include<iostream>#include<string>#include<algorithm>usingnamespace std;#define maxsize 10100//比较大小 1:a大 2:b大intcompare(string a, string b){
int flag =0;if(a.length()> b.length()){
return1;}elseif(a.length()< b.length()){
return2;}else{
//长度相等,未逆转,直接比较,低位即数值高位for(int i =0; i < a.length(); i++){
if(a[i]> b[i]){
flag =1;return1;}elseif(b[i]> a[i]){
flag =1;return2;}}}if(flag ==0){
return0;//相等}}intmain(){
string a, b;int i =0, j;int f =0;//是否产生借位int ans[maxsize];
cin >> a >> b;int c =compare