본문 바로가기
알고리즘 & 자료구조/백준

백준 1296

by 신재권 2021. 11. 14.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main1296 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String teamName = br.readLine();
		int N = Integer.parseInt(br.readLine());
		int[] rank = new int[N];
		String[] str = new String[N];

		for(int i=0; i<N; i++){
			str[i] = br.readLine();
		}
		
		Arrays.sort(str);
		
		int max = 0;
		for (int i = 0; i < N; i++) {	
			rank[i] = rank(teamName, str[i]);
			max = Math.max(max, rank[i]);
		}
		
		for(int i=0; i<N; i++){
			if(max == rank[i]){
				System.out.println(str[i]);
				break;
			}
		}

	}

	public static int rank(String teamName, String str) {

		int L = 0;
		int O = 0;
		int V = 0;
		int E = 0;
		
		for (int i = 0; i < str.length(); i++) {
			if(str.charAt(i) == 'L'){
				L++;
			}else if(str.charAt(i) == 'O'){
				O++;
			}else if(str.charAt(i) == 'V'){
				V++;
			}else if(str.charAt(i) == 'E'){
				E++;
			}
		}

		for (int i = 0; i < teamName.length(); i++) {
			if(teamName.charAt(i) == 'L'){
				L++;
			}else if(teamName.charAt(i) == 'O'){
				O++;
			}else if(teamName.charAt(i) == 'V'){
				V++;
			}else if(teamName.charAt(i) == 'E'){
				E++;
			}
		}

		return ((L+O)*(L+V)*(L+E)*(O+V)*(O+E)*(V+E)) % 100;

	}

}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 1333  (0) 2021.11.16
백준 1308  (0) 2021.11.15
백준 1268  (0) 2021.11.13
백준 1260  (0) 2021.11.07
백준 2798  (0) 2021.11.05