【CPE】一顆星選集(Part 7) | C++

更新於 發佈於 閱讀時間約 6 分鐘

Odd Sum

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724

中文題目:https://zerojudge.tw/ShowProblem?problemid=c022

#include <iostream>
using namespace std;

int main(){
    int T;
    cin >> T;
    for (int i = 1; i <= T; i++) {
        int a, b;
        cin >> a >> b;
        if (a % 2 == 0) {
            a += 1;
        }
        if (b % 2 == 0) {
            b -= 1;
        }
        int num=(b-a)/2+1;
        int total;
        total=(a+b)/2*num;
        cout << "Case " << i << ": ";
        cout << (a + b) / 2 * ((b - a) / 2 + 1) << "\n";
    }
return 0;
}

Beat the Spread!

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1753

中文題目:https://zerojudge.tw/ShowProblem?problemid=c004

#include <iostream>
using namespace std;

int main() {
    int T, s, d;
    cin >> T;
    while (T--){
        cin >> s >> d;
        if ((s + d) % 2 || s < d) cout << "impossible\n";
        else {
            cout << (s+d)/2 << " " << (s-d)/2 << "\n";
        }
    }
    return 0;
}

Symmetric Matrix

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2324#google_vignette

中文題目:https://zerojudge.tw/ShowProblem?problemid=e513

#include <iostream>
using namespace std;

int main() {
    int T, n;
    char ch;
    cin >> T;
    for (int Case = 1; Case <= T; Case++){
        cin >> ch >> ch >> n;
        long long a[n][n];
        bool flag = true;
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                cin >> a[i][j];
                if (a[i][j] < 0) flag = false;
            }
        }
        cout << "Test #" << Case << ": ";
        if (!flag){
            cout << "Non-symmetric.\n";
            continue;
        }     
        for (int i = 0; i <= n/2; i++){
            for (int j = 0; j < n-i; j++){
                if (a[i][j] != a[n-1-i][n-1-j]){
                    flag = false;
                    break;
                }
            }
        }
        if (flag) cout << "Symmetric.\n";
        else cout << "Non-symmetric.\n";
    }
    return 0;
}


留言
avatar-img
留言分享你的想法!
avatar-img
Jim的沙龍
1會員
31內容數
Jim的沙龍的其他內容
2025/08/14
What is the Probability!! 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997 中文題目:https:
2025/08/14
What is the Probability!! 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997 中文題目:https:
2025/08/14
TeX Quotes 題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208 中文題目:https://zerojudge.t
2025/08/14
TeX Quotes 題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208 中文題目:https://zerojudge.t
2025/08/13
Problem J: Summing Digits 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2307#google_vign
2025/08/13
Problem J: Summing Digits 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2307#google_vign
看更多