diff --git a/BJ_13567.java b/BJ_13567.java new file mode 100644 index 0000000..4486ebb --- /dev/null +++ b/BJ_13567.java @@ -0,0 +1,44 @@ +package baekjoon; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +class BJ_13567 { + + int mapSize, cmdCnt, curX, curY, dir; + int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 }; + + void solve() { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + try { + StringTokenizer st = new StringTokenizer(br.readLine()); + mapSize = Integer.parseInt(st.nextToken()); + cmdCnt = Integer.parseInt(st.nextToken()); + for (int i = 0; i < cmdCnt; i++) { + st = new StringTokenizer(br.readLine()); + String cmd = st.nextToken(); + int dis = Integer.parseInt(st.nextToken()); + if (cmd.equals("MOVE")) { + curX += dx[dir] * dis; + curY += dy[dir] * dis; + } else if (cmd.equals("TURN")) { + if (dis == 0) dir = (dir + 1) % 4; + else dir = (dir + 3) % 4; + } + if (curX < 0 || curX >= mapSize || curY < 0 || curY >= mapSize) { + System.out.println(-1); + return; + } + } + System.out.println(curX + " " + curY); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new BJ_13567().solve(); + } +} \ No newline at end of file diff --git a/BJ_14467.java b/BJ_14467.java new file mode 100644 index 0000000..b123815 --- /dev/null +++ b/BJ_14467.java @@ -0,0 +1,38 @@ +package baekjoon; + +import java.util.*; + +public class BJ_14467 { + static ArrayList> list = new ArrayList>(); + + public static void main (String[]args){ + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int sum = 0; + + for(int i=0; i<101; i++){ + list.add(new ArrayList()); + } + + for(int i=0; i pq = new PriorityQueue(new ASC_2870()); + String tmp; + char cTmp; + String save; + for(int i = 0 ; i < N ; i++) { + tmp = br.readLine(); + for(int j = 0 ; j < tmp.length() ; j++) { + cTmp = tmp.charAt(j); + save = ""; + boolean check = false; + while(cTmp >= '0' && cTmp <= '9') { + if(save.length() == 0 && cTmp == '0') { + save = "0"; + check = true; + } + else { + // 첫 번째 값이 아닌 경우. 0 ~ 9가 다 가능 + if(check) { // 첫 번째 값이 0인 경우. + if(cTmp != '0') { // 첫 번째가 0이나, 두 번재는 0이 아니다. + save = ""; + save += cTmp; // 두 번째 값을 첫 번째로 사용. + check = false; + } + // 첫 번째와 두 번째가 모두 0이다. 이는 0 그대로. > 아무것도 하지 않아도 됨 + } + else // 첫 번째 값이지만 0이 아닌 경우 어떤 값이 들어와도 상관 없음. + save += cTmp; + } + j++; + if(j >= tmp.length()) + break; + cTmp = tmp.charAt(j); + } + if(save.length() == 0) + continue; + pq.add(save); + } + } + + + while(!pq.isEmpty()) { + String now = pq.poll(); + System.out.println(now); + } + } +} +class ASC_2870 implements Comparator{ + + public int compare(String v1, String v2) { + if(v1.length() == v2.length()) + return v1.compareTo(v2) < 0 ? -1 : 1; + else + return v1.length() - v2.length() < 0 ? -1 : 1; + } +} \ No newline at end of file diff --git a/BJ_4659.java b/BJ_4659.java new file mode 100644 index 0000000..3cb4f49 --- /dev/null +++ b/BJ_4659.java @@ -0,0 +1,65 @@ +package baekjoon; + +import java.util.*; +/* + * 비밀번호 발음하기 + * + * 1. 모음(a,e,i,o,u) 하나를 반드시 포함하여야 한다. + * 2. 모음이 3개 혹은 자음이 3개 연속으로 오면 안 된다. + * 3. 같은 글자가 연속적으로 두번 오면 안되나, ee 와 oo는 허용한다. + * + * */ +public class BJ_4659 { + static final char[] vowels = {'a' ,'e' ,'i' ,'o' , 'u'}; + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while(true) { + String word = sc.nextLine(); + StringBuilder ans = new StringBuilder(""); + + if(word.equals("end")) break; + + ans.append("<").append(word).append("> "); + + if(!check(word)) { + ans.append("is not acceptable."); + }else { + ans.append("is acceptable."); + } + System.out.println(ans.toString()); + } + } + + private static boolean check(String word) { + boolean hasVowel = false; + int vowel = 0, consonant = 0; + char pre = ' '; + for(int i =0, l = word.length(); i=3 || consonant>=3) return false; + + // 3. 같은 글자가 연속적으로 두번 오면 안되나, ee 와 oo는 허용한다. + if(pre == word.charAt(i)&& pre != 'e' && pre != 'o') return false; + pre = word.charAt(i); + } + if(hasVowel)return true; + return false; + } + +} \ No newline at end of file diff --git a/BJ_5635.java b/BJ_5635.java new file mode 100644 index 0000000..930f2d2 --- /dev/null +++ b/BJ_5635.java @@ -0,0 +1,134 @@ +package baekjoon; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class BJ_5635 { + + private String name; + private String elderName; + private String olderName; + + private int minDayOfAge,maxDayOfAge=0; + private int minMonthOfAge,maxMonthOfAge=0; + private int minYearOfAge,maxYearOfAge =0; + + + public static void main(String[] args) throws IOException { + + BJ_5635 main = new BJ_5635(); + main.go(); + + } + + public void go() throws IOException{ + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + StringTokenizer st; + int[] info = new int[3]; + + st = new StringTokenizer(br.readLine(), " "); + + olderName = st.nextToken(); + elderName = olderName; + + minDayOfAge = Integer.parseInt(st.nextToken()); + minMonthOfAge = Integer.parseInt(st.nextToken()); + minYearOfAge = Integer.parseInt(st.nextToken()); + + maxDayOfAge = minDayOfAge; + maxMonthOfAge = minMonthOfAge; + maxYearOfAge = minYearOfAge; + + while(n > 1){ + + st = new StringTokenizer(br.readLine(), " "); + name = st.nextToken(); + + for(int i=0; i<3; ++i){ + info[i]=Integer.parseInt(st.nextToken()); + } + + elderName = findMinAge(name, info); + olderName = findMaxAge(name, info); + n--; + } + + System.out.println(elderName); + System.out.println(olderName); + + } + //나이 어린 사람 + public String findMinAge(String name, int[] info){ + + if(minYearOfAge > info[2]){ + return elderName; + + }else if(minYearOfAge == info[2]){ + if(minMonthOfAge > info[1]){ + return elderName; + + }else if(minMonthOfAge == info[1]){ + if(minDayOfAge > info[0]){ + return elderName; + }else{ + changeMinValue(info); + return name; + } + }else{ + changeMinValue(info); + return name; + } + }else{ + changeMinValue(info); + return name; + } + } + + //나이 많은 사람 + public String findMaxAge(String name, int[] info){ + + if(maxYearOfAge < info[2]){ + return olderName; + + }else if(maxYearOfAge == info[2]){ + if(maxMonthOfAge < info[1]){ + return olderName; + + }else if(maxMonthOfAge == info[1]){ + if(maxDayOfAge < info[0]){ + return olderName; + }else{ + changeMaxValue(info); + return name; + } + }else{ + changeMaxValue(info); + return name; + } + }else{ + changeMaxValue(info); + return name; + } + } + + public void changeMinValue(int[] info){ + + this.minYearOfAge =info[2]; + this.minMonthOfAge = info[1]; + this.minDayOfAge =info[0]; + + } + + public void changeMaxValue(int[] info){ + + this.maxYearOfAge =info[2]; + this.maxMonthOfAge = info[1]; + this.maxDayOfAge =info[0]; + + } +} \ No newline at end of file diff --git a/BJ_7785.java b/BJ_7785.java new file mode 100644 index 0000000..f5cd6c2 --- /dev/null +++ b/BJ_7785.java @@ -0,0 +1,31 @@ +package baekjoon; + +import java.util.*; +public class BJ_7785{ + public static void main(String[] args) { + int N = 0; + HashMap hash=new HashMap<>(); + Scanner in=new Scanner(System.in); + N=in.nextInt(); + String[][] map=new String[N][2]; + + for(int i=0;i arr=new ArrayList<>(); + + for(String str: hash.keySet()) + if(hash.get(str).equals("enter")) arr.add(str); + + + Collections.sort(arr, Collections.reverseOrder()); + + + for(String str:arr) + System.out.println(str); + } + +} \ No newline at end of file