삐까냥의 파도타기

카카오 블라인드 채용 신입 공채 3차 코딩 테스트) 4번 문제 본문

코딩/카카오 코딩 테스트

카카오 블라인드 채용 신입 공채 3차 코딩 테스트) 4번 문제

금손형아 2018. 3. 7. 11:27


문제 출처 : http://tech.kakao.com/2017/11/14/kakao-blind-recruitment-round-3/


그대로 구현했는데,


테스트케이스가 적어 어떨지 모르겠네요.


public class kakao_3_4 {

public static void main(String[] args) {

solution(new String[]{"ABCDEFG", "12:00,12:14,HELLO,CDEFGAB", "13:00,13:05,WORLD,ABCDEF"});

solution(new String[]{"CC#BCC#BCC#BCC#B", "03:00,03:30,FOO,CC#B", "04:00,04:08,BAR,CC#BCC#BCC#B"});

solution(new String[]{"ABC", "12:00,12:14,HELLO,C#DEFGAB", "13:00,13:05,WORLD,ABCDEF"});

}

static void solution(String[] playList) {

String rememberSong = getChangedSong(playList[0]);

String name = "None";

int playTime = 0;

for (int i = 1; i < playList.length; i++) {

Music tempMusic = new Music(playList[i]);

if (tempMusic.getPlayResult().contains(rememberSong)) {

int tempPlayTime = tempMusic.getPlayTimeByMinute();

if (playTime < tempPlayTime) {

name = tempMusic.getName();

playTime = tempPlayTime;

}

}

}

System.out.println(name);

}

static String getChangedSong(String song) {

String tempSong = song;

tempSong = tempSong.replaceAll("C#", "V");

tempSong = tempSong.replaceAll("D#", "W");

tempSong = tempSong.replaceAll("F#", "X");

tempSong = tempSong.replaceAll("G#", "Y");

tempSong = tempSong.replaceAll("A#", "Z");

return tempSong;

}

}


class Music {

String name, playResult;

int playTimeByMinute;

Music (String playInfo) {

String[] info = playInfo.split(",");

setPlayTime(info[0], info[1]);

name = info[2];

setPlayNumAndPlayResult(info[3]);

}

void setPlayTime(String startTime, String endTime) {

int startTimeByMinute = getTime(startTime);

int endTimeByMinute = getTime(endTime);

playTimeByMinute = endTimeByMinute - startTimeByMinute;

}

int getTime(String time) {

String[] timeInfo = time.split(":");

int minuteTime = (Integer.valueOf(timeInfo[0]) * 60) + (Integer.valueOf(timeInfo[1]));

return minuteTime;

}

void setPlayNumAndPlayResult(String song) {

String ChangedSong = getChangedSong(song);

int musicLength = ChangedSong.length();

int fullPlay = playTimeByMinute / musicLength;

int partialPlay = playTimeByMinute % musicLength;

StringBuffer tempResult = new StringBuffer();

for (int i = 0; i < fullPlay; i++) {

tempResult.append(ChangedSong);

}

tempResult.append(ChangedSong.substring(0, partialPlay));

playResult = tempResult.toString();

}

String getChangedSong(String song) {

String tempSong = song;

tempSong = tempSong.replaceAll("C#", "V");

tempSong = tempSong.replaceAll("D#", "W");

tempSong = tempSong.replaceAll("F#", "X");

tempSong = tempSong.replaceAll("G#", "Y");

tempSong = tempSong.replaceAll("A#", "Z");

return tempSong;

}

String getPlayResult() {

return playResult;

}

String getName() {

return name;

}

int getPlayTimeByMinute() {

return playTimeByMinute;

}