Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dda6145

Browse files
Merge pull request TecheerB#11 from Gnu-Kenny/master
[211122] 완전탐색
2 parents 5488138 + 0d346ee commit dda6145

File tree

6 files changed

+197
-1
lines changed

6 files changed

+197
-1
lines changed

‎GnuPark/BOJ/2231.java‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package BOJ;
2+
import java.io.BufferedReader;
3+
import java.io.InputStreamReader;
4+
import java.io.IOException;
5+
6+
public class 2231 {
7+
public static void main(String[] args) throws IOException {
8+
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
int N = Integer.parseInt(br.readLine());
12+
13+
int result = 0;
14+
15+
16+
for(int i = 0; i < N; i++) {
17+
int number = i;
18+
int sum = 0; // 각 자릿수 합 변수
19+
20+
while(number != 0) {
21+
sum += number % 10; // 각 자릿수 더하기
22+
number /= 10;
23+
}
24+
25+
// i 값과 각 자릿수 누적합이 같을 경우 (생성자를 찾았을 경우)
26+
if(sum + i == N) {
27+
result = i;
28+
break;
29+
}
30+
31+
}
32+
33+
System.out.println(result);
34+
}
35+
}

‎GnuPark/BOJ/2798.java‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package BOJ;
2+
import java.io.BufferedReader;
3+
import java.io.InputStreamReader;
4+
import java.io.IOException;
5+
import java.util.StringTokenizer;
6+
7+
public class 2798 {
8+
public static void main(String[] args) throws IOException {
9+
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
12+
13+
int N = Integer.parseInt(st.nextToken());
14+
int M = Integer.parseInt(st.nextToken());
15+
16+
int[] arr = new int[N];
17+
18+
st = new StringTokenizer(br.readLine(), " ");
19+
for (int i = 0; i < N; i++) {
20+
arr[i] = Integer.parseInt(st.nextToken());
21+
}
22+
23+
int result = search(arr, N, M);
24+
System.out.println(result);
25+
}
26+
27+
28+
// 탐색
29+
static int search(int[] arr, int N, int M) {
30+
int result = 0;
31+
32+
// 3개를 고르기 때문에 첫번째 카드는 N - 2 까지만 순회
33+
for (int i = 0; i < N - 2; i++) {
34+
35+
// 두 번째 카드는 첫 번째 카드 다음부터 N - 1 까지만 순회
36+
for (int j = i + 1; j < N - 1; j++) {
37+
38+
// 세 번째 카드는 두 번째 카드 다음부터 N 까지 순회
39+
for (int k = j + 1; k < N; k++) {
40+
41+
// 3개 카드의 합 변수 temp
42+
int temp = arr[i] + arr[j] + arr[k];
43+
44+
// M과 세 카드의 합이 같다면 temp return 및 종료
45+
if (M == temp) {
46+
return temp;
47+
}
48+
49+
// 세 카드의 합이 이전 합보다 크면서 M 보다 작을 경우 result 갱신
50+
if(result < temp && temp < M) {
51+
result = temp;
52+
}
53+
}
54+
}
55+
}
56+
57+
// 모든 순회를 마치면 result 리턴
58+
return result;
59+
}
60+
}

‎GnuPark/gnu.java‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public static int[] solution(int[] answers) {
5+
int[] answer;
6+
7+
int[] a = new int[] { 1, 2, 3, 4, 5 };
8+
int[] b = new int[] { 2, 1, 2, 3, 2, 4, 2, 5 };
9+
int[] c = new int[] { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 };
10+
11+
int[] score = new int[3];
12+
13+
// score[]에 수포자별 맞힌 갯수
14+
for (int i = 0; i < answers.length; i++) {
15+
if (answers[i] == a[i % 5])
16+
score[0]++;
17+
if (answers[i] == b[i % 8])
18+
score[1]++;
19+
if (answers[i] == c[i % 10])
20+
score[2]++;
21+
}
22+
23+
// 가장 높은 점수
24+
int max = 0;
25+
for (int i = 0; i < 3; i++) {
26+
if (score[i] > max) {
27+
max = score[i];
28+
}
29+
}
30+
31+
// 가장 높은 점수를 받은 사람 수
32+
int maxCount = 0;
33+
for (int i = 0; i < 3; i++) {
34+
if (score[i] == max) {
35+
maxCount++;
36+
}
37+
}
38+
39+
answer = new int[maxCount];
40+
int idx = 0;
41+
for (int i = 0; i < 3; i++) {
42+
if (score[i] == max)
43+
answer[idx++] = i + 1;
44+
}
45+
return answer;
46+
}
47+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public int[] solution(int brown, int yellow) {
3+
int[] answer = new int[2];
4+
5+
int area = brown + yellow; // 전체 격자 개수
6+
7+
for (int i = 1; i <= area; i++) {
8+
int row = i; // 세로
9+
int col = area / row; // 가로
10+
11+
// 카펫의 가로 길이는 세로 길이와 같거나, 세로 길이보다 길다.
12+
if (row > col)
13+
continue;
14+
15+
if ((row - 2) * (col - 2) == yellow) {
16+
answer[0] = col;
17+
answer[1] = row;
18+
return answer;
19+
}
20+
21+
}
22+
23+
return answer;
24+
}
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package programmers.정렬;
2+
3+
import java.util.*;
4+
5+
public class level01_Sort {
6+
public static int[] solution(int[] array, int[][] commands) {
7+
int[] answer = new int[commands.length];
8+
for (int i = 0; i < commands.length; i++) {
9+
int[] command = new int[commands[i][1] - commands[i][0] + 1];
10+
for (int j = 0, k = commands[i][0]; j <= commands[i][1] - commands[i][0]; j++, k++) {
11+
command[j] = array[k - 1];
12+
}
13+
Arrays.sort(command);
14+
answer[i] = command[commands[i][2] - 1];
15+
}
16+
17+
return answer;
18+
}
19+
20+
public static void main(String[] args) {
21+
int[] array = { 1, 5, 2, 6, 3, 7, 4 };
22+
int[][] commands = { { 2, 5, 3 }, { 4, 4, 1 }, { 1, 7, 3 } };
23+
int[] answer = {};
24+
answer = solution(array, commands);
25+
26+
for (int i = 0; i < answer.length; i++) {
27+
System.out.print(answer[i]);
28+
}
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /