728x90
๋ค์ด๋ฒ ์ฝํ ๋ ์ด๋ค ์์ผ๋ก ๋์ค๋์ง ์ฐพ์๋ณด๋ค๊ฐ ๋ฐ๊ฒฌํ ๋ธ๋ก๊ทธ ๊ธ์ด๋ค.
์์ธ์ง ์ง๊ธ์ ํ๋ก๊ทธ๋๋จธ์ค์์ ๋ฌธ์ ๊ฐ ๋ด๋ ค๊ฐ ๊ฒ ๊ฐ์๋ฐ, ๋์ด๋๊ฐ ๋ฎ์๋ณด์ฌ์ ๊ทธ๋ฅ ํ๋ฒ ํ์ด๋ณด์๋ค
https://drcode-devblog.tistory.com/262
๋์ ํ์ด
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
int scores[11][11];
string solution(int t){
string answer = "";
for (int i = 0; i < t; ++i){ // ์ต๊ณ ์ , ์ฃ์ ์ ์ฒ๋ฆฌ
int maxs = *max_element(scores[i], scores[i] + t);
int mins = *min_element(scores[i], scores[i] + t);
if(scores[i][i] == maxs) scores[i][i]=-1;
else if(scores[i][i] == mins) scores[i][i]=-1;
}
for (int i = 0; i < t; ++i){
int sum = 0;
int cnt = 0;
for (int j = 0; j < t; ++j){
if(scores[j][i]<0) continue;
sum += scores[j][i];
cnt++;
}
sum /= cnt;
if(sum>=90) answer+="A";
else if(sum>=80) answer+="B";
else if(sum>=70) answer+="C";
else if(sum>=50) answer+="D";
else answer+="F";
}
return answer;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t;
cin >> t;
for (int i = 0; i < t; ++i){
for (int j = 0; j < t; ++j){
cin >> scores[i][j];
}
}
cout << solution(t);
return 0;
}
728x90
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++/PGS] Lv.2 : ์์/์์ฅ (ํด์) (0) | 2023.04.13 |
---|---|
[C++/PGS] Lv.2 : ์ ํ๋ฒํธ ๋ชฉ๋ก (ํด์) (0) | 2023.04.13 |
[C++/PGS] Lv.1 : ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ (์นด์นด์ค ๊ธฐ์ถ) (0) | 2023.04.12 |
[C++/PGS] Lv.1 : ์ฑ๊ฒฉ ์ ํ ๊ฒ์ฌํ๊ธฐ (์นด์นด์ค ๊ธฐ์ถ) (0) | 2023.04.12 |
[C++/PGS] Lv.1 : ๊ฐ์ธ์ ๋ณด ์์ง ์ ํจ๊ธฐ๊ฐ (์นด์นด์ค ๊ธฐ์ถ) (0) | 2023.04.12 |