L1-080 乘法口訣數列 分數 20

Frodnx發表於2024-08-20

注意:不是每次找陣列最後兩個元素做乘積!

// 11'39"
#include <bits/stdc++.h>
using namespace std;
void func(vector<int>& v, int now)
{
    int num = v[now] * v[now - 1];
    vector<int> tmp;
    if(num == 0)
    {
    	v.push_back(0);
		return; 
	}
    while(num)
    {
        tmp.push_back(num % 10);
        num /= 10;
    }
    reverse(tmp.begin(),tmp.end());
    for(auto c : tmp)
        v.push_back(c);
}
int main()
{
    int a1, a2, n;
    cin >> a1 >> a2 >> n;
    vector<int> v;
    v.push_back(a1);
    v.push_back(a2);
    int now = 1;
    while(v.size() < n)
        func(v,now ++);
    for(int i = 0; i < n; ++ i)
        cout << v[i] << ((i == n-1) ? "" : " ");
    return 0;
}

相關文章