Skip to content

Commit 881a239

Browse files
Merge pull request #28 from algorithm-cote-study/yeji/backjun
Yeji/backjun
2 parents ee6a233 + 204eaab commit 881a239

File tree

12 files changed

+450
-2
lines changed

12 files changed

+450
-2
lines changed

src/main/java/sgyj/backjun/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 백준 알고리즘 문제풀이
22

3-
43
## 문제 업로드 기준
54

65
### [solved.ac](https://solved.ac/en/class) 사이트에 표기 된 class 별로 문제 풀어보기
7-
### class외의 문제를 풀었을 경우에는 etc 패키지에 따로 분류하기
6+
7+
### class외의 문제를 풀었을 경우에는 etc 패키지에 따로 분류하기
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package sgyj.backjun.yeji.class1p;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.util.Arrays;
8+
9+
// 최소, 최대
10+
public class Main10818 {
11+
12+
public static void main ( String[] args ) {
13+
try(InputStreamReader in = new InputStreamReader(System.in);
14+
BufferedReader br = new BufferedReader( in );){
15+
16+
int n = Integer.parseInt( br.readLine() );
17+
int min = Integer.MAX_VALUE;
18+
int max = Integer.MIN_VALUE;
19+
int[] s = Arrays.stream( br.readLine().split( " " ) ).mapToInt( Integer::parseInt ).toArray();
20+
21+
for(int r : s){
22+
min = Math.min( r, min );
23+
max = Math.max( r,max );
24+
}
25+
26+
System.out.println(min + " " + max);
27+
28+
}catch ( IOException ex ){
29+
ex.printStackTrace();
30+
}
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package sgyj.backjun.yeji.class1p;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
8+
// 아스키코드
9+
public class Main10951 {
10+
11+
public static void main ( String[] args ) {
12+
try( InputStreamReader in = new InputStreamReader( System.in );
13+
BufferedReader br = new BufferedReader( in );){
14+
15+
System.out.println(br.read());
16+
17+
}catch ( IOException ex ){
18+
ex.printStackTrace();
19+
}
20+
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package sgyj.backjun.yeji.class1p;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
8+
// A+B - 5
9+
public class Main10952 {
10+
11+
public static void main ( String[] args ) {
12+
try( InputStreamReader inputStreamReader = new InputStreamReader( System.in );
13+
BufferedReader br = new BufferedReader( inputStreamReader );){
14+
StringBuilder answer = new StringBuilder();
15+
String line;
16+
while ( (line = br.readLine()) != null && !line.isBlank() ){
17+
int[] s = Arrays.stream(line.split( " " ) ).mapToInt( Integer::parseInt ).toArray();
18+
if(s[0]+s[1] != 0){
19+
answer.append( s[0]+s[1] ).append( "\n" );
20+
}
21+
}
22+
System.out.println(answer);
23+
}catch ( IOException ex ){
24+
ex.printStackTrace();
25+
}
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package sgyj.backjun.yeji.class1p;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
import java.util.HashSet;
8+
import java.util.Set;
9+
10+
public class Main11720 {
11+
12+
public static void main ( String[] args ) {
13+
try(InputStreamReader in = new InputStreamReader( System.in );
14+
BufferedReader br = new BufferedReader( in );){
15+
16+
br.readLine();
17+
int result = Arrays.stream( br.readLine().split( "" ) ).mapToInt( Integer::parseInt ).sum();
18+
System.out.println(result);
19+
20+
}catch ( IOException ex ){
21+
ex.printStackTrace();
22+
}
23+
}
24+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package sgyj.backjun.yeji.class1p;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
// OX퀴즈
8+
public class Main8958 {
9+
10+
public static void main ( String[] args ) {
11+
try(InputStreamReader in = new InputStreamReader( System.in);
12+
BufferedReader br = new BufferedReader( in );){
13+
14+
int n = Integer.parseInt(br.readLine());
15+
int[] answer = new int[n];
16+
17+
for(int i=0; i<n; i++){
18+
answer[i] = solution(br.readLine().split( "" ));
19+
}
20+
21+
for ( int a : answer ){
22+
System.out.println(a);
23+
}
24+
25+
}catch ( IOException ex ){
26+
ex.printStackTrace();
27+
}
28+
}
29+
30+
private static int solution(String[] input){
31+
int result = 0;
32+
33+
int n = 1;
34+
for(String in : input){
35+
if("O".equals( in )){
36+
result += n;
37+
n++;
38+
}else{
39+
n = 1;
40+
}
41+
}
42+
43+
return result;
44+
}
45+
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package sgyj.backjun.yeji.etc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
8+
// 부분수열의 합
9+
public class Main1182 {
10+
11+
private static int[] data;
12+
private static int target;
13+
private static int answer;
14+
private static int N;
15+
16+
public static void main ( String[] args ) throws IOException {
17+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
18+
int[] input = Arrays.stream(br.readLine().split( " " )).mapToInt( Integer::parseInt ).toArray();
19+
data = Arrays.stream( br.readLine().split( " " ) ).mapToInt( Integer::parseInt ).toArray();
20+
target = input[1];
21+
N = input[0];
22+
23+
dfs(0,0);
24+
25+
System.out.println(target == 0 ? answer - 1 : answer);
26+
}
27+
28+
private static void dfs(int dep, int sum) {
29+
if (dep == N) {
30+
if (sum == target)
31+
answer++;
32+
return;
33+
}
34+
35+
dfs(dep + 1, sum + data[dep]);
36+
dfs(dep + 1, sum);
37+
}
38+
39+
40+
41+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package sgyj.backjun.yeji.etc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
// 빗물
9+
public class Main14719 {
10+
11+
static int[] map;
12+
13+
static int ret, left , right;
14+
15+
public static void main ( String[] args ) throws IOException {
16+
BufferedReader br = new BufferedReader( new InputStreamReader( System.in));
17+
StringTokenizer st = new StringTokenizer( br.readLine());
18+
int H = Integer.parseInt(st.nextToken());
19+
int W = Integer.parseInt(st.nextToken());
20+
map = new int[W];
21+
ret = left = right = 0;
22+
23+
st = new StringTokenizer(br.readLine());
24+
for (int i = 0; i < W; i++) {
25+
int N = Integer.parseInt(st.nextToken());
26+
map[i] = N;
27+
}
28+
29+
// 인덱스마다 모이는 빗물 계산 ( 1번째 기둥과 마지막 기둥의 위치는 제외 )
30+
for (int i = 1; i < W - 1; i++) {
31+
left = right = 0;
32+
// 왼쪽에서 가장 높은 건물의 높이
33+
for (int j = 0; j < i; j++) {
34+
left = Math.max(map[j], left);
35+
}
36+
// 오른쪽에서 가장 높은 건물의 높이
37+
for (int j = i + 1; j < W; j++) {
38+
right = Math.max(map[j], right);
39+
}
40+
// 더 낮은 건물을 기준으로 현재 인덱스에 모이는 빗물
41+
if (map[i] < left && map[i] < right) {
42+
ret += Math.min(left, right) - map[i];
43+
}
44+
}
45+
System.out.println(ret);
46+
47+
}
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package sgyj.backjun.yeji.etc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
8+
// N과 M (1)
9+
public class Main15649 {
10+
// N : 1 부터 N까지의 수
11+
// M : 조합의 갯수
12+
private static boolean[] visited;
13+
private static int[] data;
14+
private static int N,M;
15+
16+
public static void solution(){
17+
for(int i=1; i<=N; i++){
18+
visited[i] = true;
19+
data[0] = i;
20+
dfs(1);
21+
data[0] = 0;
22+
visited[i] = false;
23+
}
24+
}
25+
26+
public static void dfs( int L){
27+
if(L == M){
28+
for(int i=0; i<data.length; i++){
29+
if(data[i] != 0){
30+
System.out.print(data[i] + " ");
31+
}
32+
}
33+
System.out.println();
34+
}else{
35+
for(int j=1; j<=N; j++){
36+
if(!visited[j] ){
37+
visited[j] = true;
38+
data[L] = j;
39+
dfs(L+1);
40+
data[L] = 0;
41+
visited[j] = false;
42+
}
43+
}
44+
}
45+
}
46+
47+
public static void main ( String[] args ) throws IOException {
48+
BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
49+
String[] s = br.readLine().split( " " );
50+
N = Integer.parseInt( s[0] );
51+
M = Integer.parseInt( s[1] );
52+
visited = new boolean[N+1];
53+
data = new int[N+1];
54+
solution();
55+
}
56+
57+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package sgyj.backjun.yeji.etc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
// N과M (2)
9+
public class Main15650 {
10+
11+
public static int[] arr;
12+
public static int N, M;
13+
public static StringBuilder sb = new StringBuilder();
14+
15+
public static void main(String[] args) throws IOException {
16+
17+
BufferedReader br = new BufferedReader( new InputStreamReader( System.in));
18+
StringTokenizer st = new StringTokenizer( br.readLine());
19+
20+
N = Integer.parseInt(st.nextToken());
21+
M = Integer.parseInt(st.nextToken());
22+
23+
arr = new int[M];
24+
25+
dfs(1, 0);
26+
System.out.println(sb);
27+
28+
}
29+
30+
public static void dfs(int at, int depth) {
31+
32+
if (depth == M) {
33+
for (int val : arr) {
34+
sb.append(val).append(' ');
35+
}
36+
sb.append('\n');
37+
return;
38+
}
39+
40+
for (int i = at; i <= N; i++) {
41+
42+
arr[depth] = i;
43+
dfs(i + 1, depth + 1);
44+
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)