[Programmers] [3차]방금그곡 - 2018 KAKAO BLIND RECRUITMENT

동민·2021년 3월 11일
// [3차]방금그곡 - 2018 KAKAO BLIND RECRUITMENT
public class TheSong {
	public String solution(String m, String[] musicinfos) {

		String answer = "(None)";

		m = m.replace("C#", "c"); // #을 포함한 음계는 소문자로 변환하여 접근
		m = m.replace("D#", "d");
		m = m.replace("F#", "f");
		m = m.replace("G#", "g");
		m = m.replace("A#", "a");

		int max = 0;
		for (int i = 0; i < musicinfos.length; i++) {

			String[] info = musicinfos[i].split(",");
			int before = Integer.parseInt(info[0].split(":")[0]) * 60 + Integer.parseInt(info[0].split(":")[1]);
			int after = Integer.parseInt(info[1].split(":")[0]) * 60 + Integer.parseInt(info[1].split(":")[1]);

			info[3] = info[3].replace("C#", "c");
			info[3] = info[3].replace("D#", "d");
			info[3] = info[3].replace("F#", "f");
			info[3] = info[3].replace("G#", "g");
			info[3] = info[3].replace("A#", "a");

			String[] melody = info[3].split("");
			String total_melody = "";

			for (int j = 0; j < after - before; j++) {
				total_melody += melody[j % melody.length];
			}

			if (total_melody.contains(m)) {
				if (max < after - before) {
					max = after - before;
					answer = info[2];
				}
			}
		}
		return answer;
	}
}
profile
BE Developer

0개의 댓글