-
[백준-1713] 후보 추천하기 - Java공부/백준 2022. 7. 18. 20:37728x90
https://www.acmicpc.net/problem/1713
백준 1713번 후보 추천하기 자바 풀이
코드
import java.util.*;public class back1713 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n=scanner.nextInt();int m=scanner.nextInt();int student[]=new int [n];int re[]=new int[n];int time[]=new int[n];for(int i=0;i<m;i++){int temp=0;int num=scanner.nextInt();for(int j=0;j<n;j++){if(student[j]==0||student[j]==num){temp=j;break;}if(re[temp]>re[j]||(re[temp]==re[j]&&time[temp]>time[j])){temp=j;}}if(student[temp]!=num){student[temp]=num;re[temp]=0;time[temp]=i;}re[temp]++;}Arrays.sort(student);for(int i=0;i<n;i++){if(student[i]!=0){System.out.print(student[i]+" ");}}}}728x90반응형'공부 > 백준' 카테고리의 다른 글
[백준-10808] 알파벳 개수 - Java (0) 2022.08.19 [백준-2738] 행렬 덧셈 - Java (0) 2022.07.23 [백준-17626] Four Squares - Java (0) 2022.07.14 [백준-11727] 2xn 타일링2 - Java (0) 2022.07.14 [백준-1012] 유기농 배추 - Java (0) 2022.07.14