L1-080 乘法口訣數列

YuKiCheng發表於2024-03-30

注: 考慮兩個數字乘積是0的情況。

#include <bits/stdc++.h>
using namespace std;
int res[10000];
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	res[0] = a;
	res[1] = b;
	int pos = 2;
	for (int i = 0;; i++) {
		int ans = res[i] * res[i + 1];
		vector<int> tmp;
		if (ans == 0) {
			tmp.push_back(0);
		}
		else {
			while (ans) {
				tmp.push_back(ans % 10);
				ans /= 10;
			}
		}
		for (int j = tmp.size() - 1; j >= 0; j--) {
			res[pos++] = tmp[j];
		}
		if (pos >= c) {
			break;
		}
	}
	int flag = 0;
	for (int i = 0; i < c; i++) {
		if (flag == 0) {
			cout << res[i];
			flag = 1;
		}
		else {
			cout << " " << res[i];
		}
	}
	return 0;
}

相關文章