diff --git a/src/BaekJoon/Dltmd202/10773/Main.java b/src/BaekJoon/Dltmd202/10773/Main.java new file mode 100644 index 0000000..4bc8de8 --- /dev/null +++ b/src/BaekJoon/Dltmd202/10773/Main.java @@ -0,0 +1,30 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +/** + * 제로 + * https://www.acmicpc.net/problem/10773 + */ +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + int k = Integer.parseInt(br.readLine()); + Stack stack = new Stack<>(); + + for (int i = 0; i < k; i++) { + int data = Integer.parseInt(br.readLine()); + + if(data == 0) stack.pop(); + else stack.push(data); + } + + System.out.println( + stack.stream() + .mapToInt(Integer::intValue).sum() + ); + } +} diff --git a/src/BaekJoon/Dltmd202/10814/Main.java b/src/BaekJoon/Dltmd202/10814/Main.java new file mode 100644 index 0000000..b431c4d --- /dev/null +++ b/src/BaekJoon/Dltmd202/10814/Main.java @@ -0,0 +1,68 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; +import java.util.StringTokenizer; + +/** + * 나이순 정렬 + * https://www.acmicpc.net/problem/10814 + */ +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + int n = Integer.parseInt(br.readLine()); + Person[] people = new Person[n]; + + for (int i = 0; i < n; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + people[i] = new Person( + Integer.parseInt(st.nextToken()), + st.nextToken() + ); + } + + Arrays.stream(people) + .sorted( + Comparator.comparingInt(Person::getAge) + .thenComparing( + Comparator.comparingInt(Person::getId)) + ) + .forEach(sb::append); + + System.out.println(sb.toString().trim()); + } + + static class Person{ + static int seq = 0; + int id; + int age; + String name; + + public Person(int age, String name) { + this.id = seq++; + this.age = age; + this.name = name; + } + + public int getAge(){ + return age; + } + + public String getName(){ + return name; + } + + public int getId(){ + return id; + } + + @Override + public String toString() { + return age + " " + name + "\n"; + } + } +} diff --git a/src/BaekJoon/Dltmd202/10816/Main.java b/src/BaekJoon/Dltmd202/10816/Main.java new file mode 100644 index 0000000..16e944d --- /dev/null +++ b/src/BaekJoon/Dltmd202/10816/Main.java @@ -0,0 +1,46 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * 숫자 카드 2 + * https://www.acmicpc.net/problem/10816 + */ +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + int n = Integer.parseInt(br.readLine()); + + Map map = new HashMap<>(); + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < n; i++) { + int data = Integer.parseInt(st.nextToken()); + if(!map.containsKey(data)){ + map.put(data, 1); + } else { + map.put(data, map.get(data) + 1); + } + } + + int m = Integer.parseInt(br.readLine()); + + st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < m; i++) { + int data = Integer.parseInt(st.nextToken()); + if(!map.containsKey(data)) + sb.append(0) + .append(" "); + else { + sb.append(map.get(data)) + .append(" "); + } + } + System.out.println(sb.toString()); + } +} diff --git a/src/BaekJoon/Dltmd202/10828/Main.java b/src/BaekJoon/Dltmd202/10828/Main.java new file mode 100644 index 0000000..65e1aa3 --- /dev/null +++ b/src/BaekJoon/Dltmd202/10828/Main.java @@ -0,0 +1,37 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +/** + * 스택 + * https://www.acmicpc.net/problem/10828 + */ +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + int n = Integer.parseInt(br.readLine()); + Stack stack = new Stack<>(); + for (int i = 0; i < n; i++) { + String command = br.readLine(); + if (command.startsWith("push")){ + int data = Integer.parseInt(command.substring(5)); + stack.push(data); + } else { + if (command.equals("top")) { + sb.append(!stack.isEmpty() ? stack.peek() : -1); + } else if (command.equals("pop")){ + sb.append(!stack.isEmpty() ? stack.pop() : -1); + } else if(command.equals("size")){ + sb.append(stack.size()); + } else if(command.equals("empty")){ + sb.append(stack.isEmpty() ? 1: 0); + } + sb.append("\n"); + } + } + System.out.println(sb.toString()); + } +}