Skip to content

solve(방금그곡, 징검다리 건너기): sooyeon_230919 #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions sooyeon/week28/방금_그_곡.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.ssafy.algo230405_Random2.sooyeon.week28;

import java.util.*;

class Solution {
PriorityQueue<Music> pq;
public String solution(String m, String[] musicinfos) {
//A, A#, B, C, C#, D, D#, E, F, F#, G, G#
//A# -> a, C#-> c, D# -> d, F# -> f, G#->g 로 변환

pq = new PriorityQueue<>();

String M = "";
for(int i = 0; i < m.length(); i++) {
char cur = m.charAt(i);
if(i!= m.length()-1 && m.charAt(i+1) == '#') {
M += (cur+"").toLowerCase();
i++;
}else{
M += cur;
}
}


//시간 차이 받고, 음악 제목, 곡 시간만큼 연주 문자 붙혀서 저장

for(int i = 0; i < musicinfos.length; i++) {
int beforeH = Integer.parseInt(musicinfos[i].charAt(0)+""+musicinfos[i].charAt(1));
int beforeM = Integer.parseInt(musicinfos[i].charAt(3)+""+musicinfos[i].charAt(4));
int afterH = Integer.parseInt(musicinfos[i].charAt(6)+""+musicinfos[i].charAt(7));
int afterM = Integer.parseInt(musicinfos[i].charAt(9)+""+musicinfos[i].charAt(10));

int totalTime = (afterH - beforeH)*60 + (afterM - beforeM);

String title = "";

int point = 12;
while(true) { //제목 뽑기
char cur = musicinfos[i].charAt(point);
point++;
if(cur == ','){ //, 나오는 순간 break
break;
}
title += cur+"";
}

String music = "";
while(true) { //악보 정보 뽑기
if(point == musicinfos[i].length()) {
break;
}
char cur = musicinfos[i].charAt(point);

if(point != musicinfos[i].length()-1 && musicinfos[i].charAt(point+1)=='#') {
music += (cur+"").toLowerCase();
point+=2;
}else{
music += cur;
point +=1;
}
}


String totalMusic = ""; //총 악보 정보
int musicNum = music.length();
for(int j = 0; j < (totalTime/musicNum); j++) {
totalMusic += music;
}
totalMusic += music.substring(0, totalTime%musicNum);


//totalTime 이 큰 순서로 pq에 넣기
pq.offer(new Music(totalTime, title, totalMusic));

}

int size = pq.size();
for(int i = 0; i < size; i++) {
Music curM = pq.poll();
if(curM.music.contains(M)) {
return curM.title;
}

}

return "(None)";
}

}
class Music implements Comparable<Music>{
int time;
String title;
String music;

Music(int time, String title, String music){
this.time = time;
this.title = title;
this.music = music;
}

@Override
public int compareTo(Music o) {
return o.time - this.time;
}


}
41 changes: 41 additions & 0 deletions sooyeon/week28/징검다리_건너기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.ssafy.algo230405_Random2.sooyeon.week28;

class Solution {
public int solution(int[] stones, int k) {
int left = 1;
int right = 200000000;

while(true) {
int mid = (left+right)/2;
if(left > right) {
return left-1;
}

if(isPossible(mid,stones,k)) {
left = mid+1;
}else {
right = mid-1;
}


}
}

static boolean isPossible(int num, int[] stones, int k) {
//num보다 이하인게 연속으로 k개 있으면 안된다.
int temp = 0;
for(int i = 0; i < stones.length; i++) {
if(stones[i] < num) {
temp ++;
}else {
temp = 0;
}

if(temp == k ) {
return false;
}
}
return true;
}

}