잡다한 배똥월드

728x90
코딩 테스트 풀이 체크리스트
2시간 내에 풀었는가? O
본인의 실력으로 풀었는가? O

 

 

1296번: 팀 이름 정하기

연두는 프로그래밍 대회에 나갈 팀 이름을 정하려고 한다. 미신을 믿는 연두는 이환이에게 공식을 하나 받아왔고, 이 공식을 이용해 우승할 확률이 가장 높은 팀 이름을 찾으려고 한다. 이환

www.acmicpc.net

 

 

 

 

 

import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String name = br.readLine();
		int nameLength = name.length();
        //연두 이름 기준 L, O, V, E 개수
		int L = nameLength - name.replaceAll("L", "").length();
		int O = nameLength - name.replaceAll("O", "").length();
		int V = nameLength - name.replaceAll("V", "").length();
		int E = nameLength - name.replaceAll("E", "").length();
		
        //팀 개수
		int t = Integer.parseInt(br.readLine());
		
        //확률의 가장 작은 숫자 0과 팀 이름의 사전적으로 가장 마지막인 ZZZZZZZZZZZZZZZZZZZZ로 설정
		int max = 0;
		String result = "ZZZZZZZZZZZZZZZZZZZZ";
		
        //팀 명 하나씩 꺼내면서 확률 측정하기
		for (int i = 0; i < t; i++) {
			String team = br.readLine();
			int teamLength = team.length();
			int tL = teamLength - team.replaceAll("L", "").length();
			int tO = teamLength - team.replaceAll("O", "").length();
			int tV = teamLength - team.replaceAll("V", "").length();
			int tE = teamLength - team.replaceAll("E", "").length();
			
			int total = sum(L+tL, O+tO, V+tV, E+tE);
			
			if (max < total) {
				max = total;
				result = team;
			} else if (max == total) {
				if (result.compareTo(team) > 0) {
					result = team;
				}
			}
		}
		
		System.out.println(result);
	}
	
	public static int sum(int l, int o, int v, int e) {
		return ((l+o) * (l+v) * (l+e) * (o+v) * (o+e) * (v+e)) % 100;
	}
}

 

문제 결과 메모리 시간 코드 길이
1296 맞았습니다!! 14500 KB 140 ms 1360 B

 

 

 

 

 

 

728x90

+ Recent posts