Skip to content
Merged
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
54 changes: 54 additions & 0 deletions Basic_Of_Algorithm/src/programmers_level_2/no_13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package programmers_level_2;

import java.util.ArrayList;
import java.util.HashMap;

public class no_13 {


public static void main(String[] args) {

String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"};

HashMap<String,String> map = new HashMap<>();
ArrayList<String> answerList = new ArrayList<>();

for(String str : record) {

String temp[] = str.split(" ");
String action = temp[0];
String id = temp[1];

if(action.equals("Leave")) continue;

String nick = temp[2];

map.put(id, nick);

}

for(String str : record) {

String temp[] = str.split(" ");
String action = temp[0];
String id = temp[1];

if(action.equals("Change")) continue;

String nick = map.get(id);
String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다.");

answerList.add(ans);

}


String[]answer = new String[answerList.size()];

for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i);

for(String str : answer)System.out.println(str);


}
}
70 changes: 70 additions & 0 deletions Basic_Of_Algorithm/src/programmers_level_2/no_14.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package programmers_level_2;

public class no_14 {

public static void main(String[] args) {

String p = "()))((()";

System.out.println(solution(p));

}

static String solution(String p) {

String answer = change(p);



return answer;


}
static String change(String w) {

if(w.isEmpty())return "";

String u = "";
String v = "";

int l = 0;
int r = 0;
int i;
for(i=0;i<w.length();i++) {

if(w.charAt(i)==')') l++;
else r++;

if(l==r) break;

}

u = w.substring(0,i+1);
v = w.substring(i+1,w.length());

if(isRight(u)) {
u = u + change(v);
}else {
String newU = "(" + change(v) + ")";
u = u.substring(1,u.length()-1);
u = u.replaceAll("\\(", "\\.");
u = u.replaceAll("\\)", "\\(");
u = u.replaceAll("\\.", "\\)");
newU += u;
u = newU;
}


return u;


}

static boolean isRight(String u) {

if(u.charAt(0)==')') return false;
return true;

}

}