4WA1TLE惨案
查看原帖
4WA1TLE惨案
317198
MilkyCoffee楼主2020/5/29 18:38

大家好我又又双双叒叒叕叕是那个牛奶小咖啡,我又来求助啦!

老规矩,帮忙的送关注

我的开场白依旧:虽然我代码里加了注释,但是依然可读性极差~

不多BB,A*B高精上代码!

真想用PY啊嘤嘤嘤

// #include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm> // 个人习惯
using namespace std;

string a, b;

string tim(string a, string b) { // 封装函数
	string c;
	int l1 = a.length(); // 求a长度
	int l2 = b.length(); // 求b长度
	int tmp = 0; // 每一位=0
	int jinwei = 0; // 进位=0
	for (int i = l1 - 1; i >= 0; i--) {  // 遍历a
		for (int j = l2 - 1; j >= 0; j--){ // 遍历b
			tmp = (a[i] - '0') * (b[j] - '0') + jinwei; // 求每一个结果
			jinwei = tmp / 10; // 更新进位
			tmp = tmp % 10; // 把tmp%10再加进c里
			c = char(tmp + '0') + c;
		}
	}
	if (jinwei != 0) c = char(jinwei + '0') + c; // 处理多余进位
	return c;
}

int main(){
	cin >> a >> b;
	cout << tim(a, b) << endl;
	return 0;
}

本地运行没有错啊

1*2=2

2*3=6

3*7=21

随便试了几组数据发现没错啊

但是当你输入100*100

它会输出100000000

求助啊啊啊

2020/5/29 18:38
加载中...