# zerojudge b964: APCS 2020年 1月 第 1 題 成績指標 ###### tags: `zerojudge` 題目連結: [https://zerojudge.tw/ShowProblem?problemid=b964](https://zerojudge.tw/ShowProblem?problemid=b964) 解題方法: 題目有三個目標: 1. 印出由小至大排列之後的數列 2. 尋找數列中 及格的最低分數 和 不及格的最高分數 3. 判斷所有人是 及格 或 不及格 我先是定義變數 p=999 ,f=-1 求 及格的最低分 和 不及格的最高分 接著將題目資料輸入動態陣列,並將資料排序 在輸入過程時,我對資料進行以下兩項判斷: 1. 如果輸入資料及格,但比f小,就將f設為輸入資料 2. 如果輸日資料不及格,但比p大,就將p設為輸入資料 當所有資料都輸入之後, p的值會是 *"及格的最低分"* f的值會是 *"不及格的最高分"* 如果 p的值仍是999, 代表沒有一人及格, 也就是 *"Worst Case"* f的值仍是999,則代表所有人都及格, 也就是 *"Best Case"* 以下是程式碼: ``` c #include<iostream> #include <vector> #include<algorithm> using namespace std; int main(){ vector<int> s; int n,a,p,f; p=999; f=-1; cin>>n; for(int i=0 ; i<n ; i++){ cin>>a; if(a>=60&&a<p){ p=a; }else if(a<60&&a>f){ f=a; } s.push_back(a); } sort(s.begin(),s.end()); for(int i=0 ; i<s.size() ; i++){ cout << s[i] << " "; // 輸出 10, 20, 30 }cout<<endl; if(f==-1){ cout<<"best case"<<endl; } if(f!=-1){ cout<<f<<endl; } if(p!=999){ cout<<p<<endl; } if(p==999){ cout<<"worst case"<<endl; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up