반응형
2798번
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[] arr = new int[N];
st = new StringTokenizer(br.readLine(), " ");
for(int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int result = 0;
for(int i = 0; i < N - 2; i++) {
for(int j = i + 1; j < N - 1; j++) {
for(int k = j + 1; k < N; k++) {
int temp = arr[i] + arr[j] + arr[k];
if(temp <= M) {
result = Math.max(result, temp);
}
if(temp == M) {
break;
}
}
}
}
System.out.println(result);
}
}
|
cs |
2231번
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int result = 0;
for(int i = 0; i < N; i++) {
if(N == check(i)) {
result = i;
break;
}
}
System.out.println(result);
}
public static int check(int num) {
int sum = num;
while(num > 0) {
sum += num % 10;
num /= 10;
}
return sum;
}
}
|
cs |
7568번
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int N = Integer.parseInt(br.readLine());
int[][] arr = new int[N][2];
for(int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), " ");
arr[i][0] = Integer.parseInt(st.nextToken());
arr[i][1] = Integer.parseInt(st.nextToken());
}
for(int i = 0; i < N; i++) {
int rank = 1;
for(int j = 0; j < N; j++) {
if(i == j)
continue;
if(arr[i][0] < arr[j][0] && arr[i][1] < arr[j][1]) {
rank++;
}
}
sb.append(rank + " ");
}
System.out.println(sb);
}
}
|
cs |
1018번
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static char[][] white = { { 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' }, { 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' },
{ 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' }, { 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' },
{ 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' }, { 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' },
{ 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' }, { 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' } };
static char[][] black = { { 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' }, { 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' },
{ 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' }, { 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' },
{ 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' }, { 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' },
{ 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W' }, { 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B' } };
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine(), " ");
int M = Integer.parseInt(st.nextToken());
int N = Integer.parseInt(st.nextToken());
int min = 64;
char[][] arr = new char[M][N];
for (int i = 0; i < M; i++) {
String temp = br.readLine();
for (int j = 0; j < N; j++) {
arr[i][j] = temp.charAt(j);
}
}
for (int i = 0; i < M - 7; i++) {
for (int j = 0; j < N - 7; j++) {
int white_cnt = 0;
int black_cnt = 0;
for (int k = 0; k < 8; k++) {
for (int t = 0; t < 8; t++) {
if (arr[i + k][j + t] != white[k][t])
white_cnt++;
}
}
for (int k = 0; k < 8; k++) {
for (int t = 0; t < 8; t++) {
if (arr[i + k][j + t] != black[k][t])
black_cnt++;
}
}
min = Math.min(min, Math.min(white_cnt, black_cnt));
}
}
System.out.println(min);
}
}
|
cs |
1436번
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
int num = 666;
int cnt = 1;
while(cnt != N) {
num++;
if(String.valueOf(num).contains("666"))
cnt++;
}
System.out.println(num);
}
}
|
cs |
반응형
'백준' 카테고리의 다른 글
백준 14단계 (백트래킹) (0) | 2021.05.12 |
---|---|
백준 12단계 (정렬) (0) | 2021.05.07 |
백준 10단계 (재귀) (0) | 2021.04.24 |
백준 9단계 (기본 수학2) (0) | 2021.04.21 |
백준 8단계 (기본 수학1) (0) | 2021.04.15 |