#45136: c++解題方法


dvbdarcyvolleyball@gmail.com (kuhaku1027)

學校 : 新北市私立南山高級中學
編號 : 266888
來源 : [203.71.175.235]
最後登入時間 :
2025-03-20 15:47:22
a270. 爬樓梯有益身心健康 | From: [36.229.70.6] | 發表日期 : 2025-01-13 09:30

使用min(now,next) 跟 max(now,next) 來判斷從第幾層走到第幾層

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int time;
    while(cin >> time){
        bool ok = 1;
        int a[10], floor[10];
        for(int i = 1;i <= 4;i++){
            cin >> a[i];
        }
        for(int i = 0;i < 8;i++){
            cin >> floor[i];
        }
        int now, next, runtime;
        for(int i = 0;i < 7;i++){
            now = floor[i];
            next = floor[i+1];
            runtime = 0;
            for(int j = min(now,next);j < max(now,next);j++){
                runtime += a[j];
            }
            if(runtime > time){
                cout << "no\n";
                ok = 0;
                break;
            }
        }
        if(ok){
            cout << "yes\n";
        }
    }
}

 
ZeroJudge Forum