From caf5cb4661ca0949d7f0b832189e6ce4a3963467 Mon Sep 17 00:00:00 2001 From: Dltmd202 Date: Tue, 5 Jul 2022 20:11:11 +0900 Subject: [PATCH] Feat: Add solution of #118 --- src/BaekJoon/Dltmd202/1085/Main.java | 47 +++++++++++++++++++++++++++ src/BaekJoon/Dltmd202/1181/Main.java | 48 ++++++++++++++++++++++++++++ src/BaekJoon/Dltmd202/1259/Main.java | 27 ++++++++++++++++ src/BaekJoon/Dltmd202/1436/Main.java | 31 ++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 src/BaekJoon/Dltmd202/1085/Main.java create mode 100644 src/BaekJoon/Dltmd202/1181/Main.java create mode 100644 src/BaekJoon/Dltmd202/1259/Main.java create mode 100644 src/BaekJoon/Dltmd202/1436/Main.java diff --git a/src/BaekJoon/Dltmd202/1085/Main.java b/src/BaekJoon/Dltmd202/1085/Main.java new file mode 100644 index 0000000..b918449 --- /dev/null +++ b/src/BaekJoon/Dltmd202/1085/Main.java @@ -0,0 +1,47 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + static class Coordinate{ + int x; + int y; + + public Coordinate(int x, int y) { + this.y = y; + this.x = x; + } + + private int minDifference(Coordinate c){ + return Math.min( + Math.abs(this.x - c.x), + Math.abs(this.y - c.y) + ); + } + } + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + Coordinate hansu = new Coordinate( + Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()) + ); + + Coordinate lowerLeft = new Coordinate(0 ,0); + + Coordinate upperRight = new Coordinate( + Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()) + ); + + int min = Integer.MAX_VALUE; + + min = Math.min(min, hansu.minDifference(lowerLeft)); + min = Math.min(min, hansu.minDifference(upperRight)); + + System.out.println(min); + } +} diff --git a/src/BaekJoon/Dltmd202/1181/Main.java b/src/BaekJoon/Dltmd202/1181/Main.java new file mode 100644 index 0000000..13d5258 --- /dev/null +++ b/src/BaekJoon/Dltmd202/1181/Main.java @@ -0,0 +1,48 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +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()); + String[] strs = new String[n]; + Set visited = new HashSet<>(); + + for (int i = 0; i < n; i++) { + strs[i] = br.readLine(); + } + + Arrays.sort(strs, + new Comparator() { + @Override + public int compare(String o1, String o2) { + if(o1.length() == o2.length()) + return o1.compareTo(o2); + else { + return o1.length() - o2.length(); + } + } + }); + + System.out.println( + Arrays.stream(strs) + .filter(s -> { + if(!visited.contains(s)){ + visited.add(s); + return true; + } + return false; + }) + .map(String::valueOf) + .collect(Collectors.joining("\n")) + ); + } +} diff --git a/src/BaekJoon/Dltmd202/1259/Main.java b/src/BaekJoon/Dltmd202/1259/Main.java new file mode 100644 index 0000000..d252ed4 --- /dev/null +++ b/src/BaekJoon/Dltmd202/1259/Main.java @@ -0,0 +1,27 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +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 { + while (true){ + int n = Integer.parseInt(br.readLine()); + if(n == 0) break; + char[] ary = String.valueOf(n).toCharArray(); + sb.append(getAnswer(ary)).append("\n"); + } + System.out.println(sb.toString()); + } + + private static String getAnswer(char[] ary) { + int left = 0, right = ary.length - 1; + + while (left < right){ + if(ary[left++] != ary[right--]) return "no"; + } + return "yes"; + } +} diff --git a/src/BaekJoon/Dltmd202/1436/Main.java b/src/BaekJoon/Dltmd202/1436/Main.java new file mode 100644 index 0000000..021f455 --- /dev/null +++ b/src/BaekJoon/Dltmd202/1436/Main.java @@ -0,0 +1,31 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +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 turn = Integer.parseInt(br.readLine()); + long n = 666; + + int cnt = 0; + while (true){ + char[] numArray = String.valueOf(n).toCharArray(); + if(isValid(numArray)) cnt++; + if(cnt == turn) break; + n++; + } + System.out.println(n); + } + + private static boolean isValid(char[] numArray) { + for (int i = 0; i <= numArray.length - 3; i++) { + if(numArray[i] == '6' && numArray[i + 1] == '6' && numArray[i + 2] == '6'){ + return true; + } + } + return false; + } +}