zoukankan      html  css  js  c++  java
  • 2021团体程序设计天梯赛 L1-8 乘法口诀数列

    思路:

    简单递推

    Tip:

    注意结果为0的情况

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int maxn = 1000 + 5;
    int ans[maxn];
    
    int main() {
        int a, b, n;
        cin >> a >> b >> n;
        ans[1] = a;
        ans[2] = b;
        int lastt = 3;
        for (int i = 1; i <= n; i++) {
            if (lastt > n)
                break;
            int c = ans[i] * ans[i + 1];
            if (c == 0) {
                ans[lastt++] = 0;
                continue;
            }
            stack<int> s;
            while (c) {
                s.push(c % 10);
                c /= 10;
            }
            while (!s.empty()) {
                ans[lastt++] = s.top();
                s.pop();
            }
        }
        bool first = true;
        for (int i = 1; i <= n; i++) {
            if (first) {
                first = false;
                cout << ans[i];
            } else
                cout << " " << ans[i];
        }
        return 0;
    }
    

      

  • 相关阅读:
    国际标准化组织
    SIM卡
    苹果供应商
    iOS 调试技巧
    django进阶
    web框架django初探
    jquery
    JavaScript进阶之DOM
    html和css
    前端相关html和css
  • 原文地址:https://www.cnblogs.com/Whiteying/p/14707774.html
Copyright © 2011-2022 走看看