# 成績排名 https://neoj.sprout.tw/problem/2219/ ### 題目敘述 可怕的段考考完了,老師在黑板上公布了每一個人每一科的成績分別多少。  Eevee據說每個顏色代表一種分數!? 老師除了成績之外,還告訴了每一個人這次段考總成績在班上的排名為何。如果給你所有成績以及某一位同學排名,你知道他的總分是多少嗎? ### 輸入說明 第一行有三個正整數:$W, N, K$,代表有$W$個考試科目,班上有$N$位同學,以及要詢問的同學是第$K$名。 再接下來下行有$N$行,每行有$W$個整數,每一行代表一位同學的$W$個科目成績分別為多少。 保證所有測資中: $1≤W≤1000$ $N≤K≤100$ $0≤ 每個成績≤ 100$ ### 輸出說明 請輸出一行,為該同學這次考試總分為何。 ### 範例輸入 ``` 3 5 2 0 0 10 100 100 100 99 95 93 87 78 60 85 86 100 ``` ### 範例輸出 ``` 287 By LFsWang 2020.05 ``` # Code ```cpp #include <iostream> #include <algorithm> using namespace std; void Sort(int arr[], int n){ for(int i = 1; i < n; i++) { int j = i - 1; while (j >= 0 && arr[j] < arr[j + 1]) { swap(arr[j], arr[j + 1]); j--; } } } int main(){ int W, N, K; int x, score[105] = {}; cin >> W >> N >> K; for (int i = 0; i < N; i++) { for (int j = 0; j < W; j++) { cin >> x; score[i] += x; } } Sort(score, N); cout << score[K - 1] << "\n"; } ```
×
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