太长时间不写大数了,练大数是练习字符串操作最好的方法。这种题最重要的就是细心。
我的思路是先把大数字拆成整数部分和小数部分,然后将整数部分和小数部分按位数多少找出长串和短串,然后把短串加到长串上去,用进位符carry模拟进位操作。最后再把小数部分删掉。总体来说挺麻烦的,比赛或考试时候用java就可以了。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cctype>
#include <climits>
using namespace std;
const int MAXN = 105;
const int INF = INT_MAX;
string str1, str2;
string int1, decimal1, int2, decimal2;
void exchange(string &x, string &y){
string tmp = x;
x = y;
y = tmp;
}
int main(){
// freopen("in.txt", "r", stdin);
bool flag, carry;
int cur;
while(getline(cin, str1)){
getline(cin, str2);
int length1 = str1.size(), length2 = str2.size();
//第一行拆开
flag = true;
cur = 0;
for(int i = 0; i &l