-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |