#55590: C++ 解答


yp11550392@yphs.tp.edu.tw (ZEROJUDGE)


#include <iostream>
using namespace std;

int main() {
    // 提升輸入輸出效率
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    if (cin >> t) {
        while (t--) {
            int a[4];

            // 讀入數列前四項
            for (int i = 0; i < 4; i++) {
                cin >> a[i];
            }

            // 先輸出前四項(中間帶空格)
            for (int i = 0; i < 4; i++) {
                cout << a[i] << " ";
            }

            // 判斷是等差數列還是等比數列,並計算並輸出第 5 個數
            if ((a[1] - a[0]) == (a[2] - a[1])) {
                int diff = a[1] - a[0];
                cout << a[3] + diff << "\n";
            }
            else {
                int r = a[1] / a[0];
                cout << a[3] * r << "\n";
            }
        }
    }
    return 0;
}


// 禁止抄襲 !