Advertisement

b964. APCS 第 1 題 成績指標

以下是我的程式碼

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int x, y[20],w,ww,qq;

    cin >> x;

    for (w = 0; w < x; w++) {

        cin >> y[w];

    }

    for (w = 0; w < x; w++) {

        for (ww = w + 1; ww < x; ww++) {

            if (y[w] > y[ww]) {

                qq = y[w];

                y[w] = y[ww];

                y[ww] = qq;

            }

        }

    }

    for (w = 0; w < x; w++) {

        cout << y[w] << " ";

    }

    cout << endl;

    if (y[0] >= 60) {

        cout << "best case" << endl << y[0]<<endl;

        return 0;

    }

    else if (y[w-1] < 60) {

        cout << y[w-1] << endl << "worst case" << endl;

        return 0;

    }

    else {

        for (w = 0; w < x; w++) {

            if (y[w] >= 60) {

                cout << y[w - 1] << endl << y[w] << endl;

                break;

            }

        }

    }

    return 0;

}

張貼留言

0 留言