ZJANS

a005. Eva 的回家作業

Beginner Last Update: 2025/05/16
基本運算數學

給一個數列的前四項 a1, a2, a3, a4
判斷是 等差數列 還是 等比數列
輸出第五項


解法一

✅ 完整代碼

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    
    int a, b, c, d;
    for(int i=0; i<t; i++){
        cin >> a >> b >> c >> d;
        cout << a << " " << b << " " << c << " " << d << " ";
        
        if(b/a == d/c) cout << d * (d/c) << "\n";
        else cout << d + (d-c) << "\n";
    }
    
    return 0;
}