Array_두 학생 중 꾸준히 등수가 높은 학생 구하기
✅ 첫 번째 줄에 반 학생 수, 시험 본 횟수가 주어지고 두 번째 줄부터 시험 결과가 하생 번호로 주어진다. 이 때 두 학생이 짝을 이루는데 한 학생이 다른 학생보다 모든 시험 횟수에서 등수가 높아야 한다.
예를 들어, 3 4 1 2 이면
1등: 3번 학생, 2등: 4번 학생, 3등: 1번 학생, 4등: 2번 학생
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Main {
public int solution(int n, int m, int[][] intArr){
int answer=0;
int count=0;
for(int i=1; i<n+1; i++){
for(int j=1; j<n+1; j++){ //총 경우의 수는 n*n (i*j)
for(int k=0; k<m; k++){
int pi=0; int pj=0;
for(int s=0; s<n; s++){
if(intArr[k][s]==i) pi=s;
if(intArr[k][s]==j) pj=s;
}
if(pi<pj) count++;
}
if(count==m) answer++;
}
}
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner sc= new Scanner(System.in);
int n = sc.nextInt(); // 학생 수
int m = sc.nextInt(); // 등수대로 학생 세운 것
int[][] intArr = new int[m][n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++) {
intArr[i][j] = sc.nextInt();
}
}
System.out.print(T.solution(n, m, intArr));
}
}
//⭐️input:
// 4 3
// 3 4 1 2
// 4 3 2 1
// 3 1 4 2
//⭐️output:
//3
🔵 ThingsILearned
✔️
🟢
🟢
This post is licensed under CC BY 4.0 by the author.