【題解】ZeroJudge e914: pB. 年紀計算

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e914

#include "bits/stdc++.h"
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    bool noAns = true;
    cin >> n;
    // n 年後,媽媽的年紀也不能超過 99
    for (int m = 18; m <= 99-n; m++){
        d = (m % 10) * 10 + (m / 10);
        if (d >= m) continue;
        if ((d + n) * 2 == m + n){
            noAns = false;
            cout << d << "\n";
        }
    }
    if (noAns) cout << "no answer\n";
    return 0;
}
分享本文 Share with friends