Skip to content

Commit

Permalink
Feat:Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
sa11k committed Jul 7, 2022
1 parent f4fa4b6 commit 317f6ce
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/BaekJoon/sa11k/1018/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import java.io.*;
import java.util.*;

class Main{
static boolean[][] chess;
static int result = Integer.MAX_VALUE;
static int N, M;

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");

N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

chess = new boolean[N][M]; // W : true, B : false

for(int i = 0; i<N; i++){
String s = br.readLine();
for(int j = 0; j<M; j++){
if(s.charAt(j) == 'W'){
chess[i][j] = true;
}else{
chess[i][j] = false;
}
}
}

checkchess();

System.out.println(result);

br.close();
}

static void checkchess(){
for(int i = 0; i<=N-8; i++){
for(int j = 0; j<=M-8; j++){
W_comparechess(i, j);
B_comparechess(i, j);
}
}
}

static void W_comparechess(int r, int c){
boolean condition = true;
boolean first = true;
int count = 0;

if(first != chess[r][c]) count++;

for(int i = r; i<r+8; i++){
if(i>r && first == chess[i][c]){
count++;
first = !chess[i][c];
condition = !chess[i][c];
}else if(i>r && first != chess[i][c]) {
first = chess[i][c];
condition = chess[i][c];
}
for(int j = c+1; j<c+8; j++){
if(!condition == chess[i][j]){
condition = chess[i][j];
}else{
count++;
condition = !chess[i][j];
}
}
}

if(count<result) result = count;
}

static void B_comparechess(int r, int c){
boolean condition = false;
boolean first = false;
int count = 0;

if(first != chess[r][c]) count++;

for(int i = r; i<r+8; i++){
if(i>r && first == chess[i][c]){
count++;
first = !chess[i][c];
condition = !chess[i][c];
}else if(i>r && first != chess[i][c]) {
first = chess[i][c];
condition = chess[i][c];
}
for(int j = c+1; j<c+8; j++){
if(!condition == chess[i][j]){
condition = chess[i][j];
}else{
count++;
condition = !chess[i][j];
}
}
}

if(count<result) result = count;
}

}
30 changes: 30 additions & 0 deletions src/BaekJoon/sa11k/1085/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.io.*;
import java.util.*;

class Main{
static int x, y, w, h;
static int result = Integer.MAX_VALUE;

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");

x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
w = Integer.parseInt(st.nextToken());
h = Integer.parseInt(st.nextToken());

escape(x, w-x, h-y, y);

System.out.println(result);

br.close();
}

static void escape(int left, int right, int up, int down){
if(result>left) result = left;
if(result>right) result = right;
if(result>up) result = up;
if(result>down) result = down;
}
}
35 changes: 35 additions & 0 deletions src/BaekJoon/sa11k/1181/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.*;
import java.util.*;

class Main{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
String[] word = new String[N];

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

Arrays.sort(word, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
if(s1.length() == s2.length()){
return s1.compareTo(s2);
}else{
return s1.length()-s2.length();
}
}
});

System.out.println(word[0]);

for(int i = 1; i<N; i++){
if(!(word[i].equals(word[i-1]))){
System.out.println(word[i]);
}
}

br.close();
}
}
27 changes: 27 additions & 0 deletions src/BaekJoon/sa11k/1259/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.*;
import java.util.*;

class Main{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

while(true){
String num = br.readLine();
if(Integer.parseInt(num) == 0) break;

String reverseNum = "";

for(int i = num.length()-1; i>=0; i--){
reverseNum += num.charAt(i);
}

if(num.equals(reverseNum)){
System.out.println("yes");
}else{
System.out.println("no");
}
}

br.close();
}
}
24 changes: 24 additions & 0 deletions src/BaekJoon/sa11k/1436/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.io.*;
import java.util.*;

class Main{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int check = Integer.parseInt(br.readLine());
int count = 0;
int i = 666;

while(count != check){
String num = i+"";
if(num.contains("666")){
count++;
}
i++;
}

System.out.println(i-1);


br.close();
}
}

0 comments on commit 317f6ce

Please sign in to comment.