加法
string add(string str,int x){
int carry = x;
for(int i=str.size()-1;i>=0;i--){
int cur = (str[i]-'0')+carry;
str[i] = cur%10+'0';
carry = cur/10;
}
while(carry!=0){
int d = carry%10;
str = char(d+'0')+str;
carry/=10;
}
return str;
}
减法
```cpp
除法
include <bits/stdc++.h>
using namespace std;
string div(string str,int x){ //x为除数
int carry = 0;//余数
for(int i=0;i<str.size();i++){
int cur = str[i]-'0'+carry*10;//余数和下一位结合
str[i] = cur/x + '0';
carry = cur%x;
}
int pos = 0;
while(str[pos]=='0') pos++;跳过前导0
return str.substr(pos);
}
乘法
string mul(string str,int x){
int carry = 0;
for(int i=str.size()-1;i>=0;i--){
int cur = (str[i]-'0')*x+carry;
str[i] = cur%10+'0';
carry = cur/10;
}
while(carry!=0){
int d = carry%10;
str = char(d+'0')+str;
carry/=10;
}
return str;
}