Skip to content

Commit

Permalink
Feat: Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Dltmd202 committed Jul 5, 2022
1 parent 0a14fc0 commit caf5cb4
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/BaekJoon/Dltmd202/1085/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
48 changes: 48 additions & 0 deletions src/BaekJoon/Dltmd202/1181/Main.java
Original file line number Diff line number Diff line change
@@ -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<String> visited = new HashSet<>();

for (int i = 0; i < n; i++) {
strs[i] = br.readLine();
}

Arrays.sort(strs,
new Comparator<String>() {
@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"))
);
}
}
27 changes: 27 additions & 0 deletions src/BaekJoon/Dltmd202/1259/Main.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
31 changes: 31 additions & 0 deletions src/BaekJoon/Dltmd202/1436/Main.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit caf5cb4

Please sign in to comment.