Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions 0510/BOJ/P1764/P1764_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class bj_1764_듣보잡 {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

StringBuilder sb = new StringBuilder();

int n = sc.nextInt(); // 못들어본 사람
int m = sc.nextInt(); // 못본사람

HashMap<String, String> nosee = new HashMap<>();

for(int i=0; i<n; i++) {
nosee.put(sc.next(), "no");
}

int cnt = 0;

List<String> pick = new LinkedList<>();

for(int i=0; i<m; i++) {
String word = sc.next();
if(nosee.get(word)!=null) {
cnt++;
pick.add(word);
}
}

Collections.sort(pick);

System.out.println(cnt);
for(int i=0; i<cnt; i++) {
System.out.println(pick.get(i));
}
}
}
58 changes: 58 additions & 0 deletions 0510/BOJ/P1780/P1780_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.Scanner;

public class bj_1780_종이의개수 {

static int n;
static int[][] paper;
static int[] cnt;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

n = sc.nextInt(); // N

paper = new int[n][n];

cnt = new int[3];

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
paper[i][j] = sc.nextInt();
}
} // 입력받기

divide(0, 0, n); // 분할정복!!!

for(int i=0; i<3; i++) {
System.out.println(cnt[i]);
}

}

public static boolean pcheck(int row, int col, int len) {
int num = paper[row][col];
for (int i = row; i < row + len; i++) {
for (int j = col; j < col + len; j++) {
if (paper[i][j] != num) {
return false;
}
}
}
return true;
}

public static void divide(int row, int col, int len) {
if(pcheck(row, col, len)) {
int num = paper[row][col];
cnt[num + 1] ++; //-1때문에 "값+1 == 인덱스"
}else {
int nextLen = len / 3;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
divide(row + i*nextLen, col + j*nextLen, nextLen);
}
}
}
}
}
33 changes: 33 additions & 0 deletions 0510/BOJ/P1927/P1927_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.PriorityQueue;
import java.util.Scanner;

public class bj_1927_최소힙 {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

PriorityQueue<Integer> pq = new PriorityQueue<>();

int n = sc.nextInt();

StringBuilder sb = new StringBuilder();

for(int i = 0; i<n; i++) {

int num = sc.nextInt();

if(num == 0) {
if(pq.isEmpty()) {
sb.append(0).append("\n");
}else {
sb.append(pq.poll()).append("\n");
}
}else {
pq.add(num);
//System.out.println(sb.toString());
}
}

System.out.println(sb);
}
}
26 changes: 26 additions & 0 deletions 0510/Programmers/Lv1/없는숫자더하기_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

public class lv1_없는숫자더하기 {
public static void main(String[] args) {

int[] numbers = {1,2,3,4,6,7,8,0};

//

int answer = 0;

for(int i=0; i<=9; i++) {
boolean flag = false;
for(int j=0; j<numbers.length; j++) {
if(numbers[j] == i) {
flag = true;
}
}
if(!flag) {
answer+=i;
}
}

System.out.println(answer);
}

}
48 changes: 48 additions & 0 deletions 0510/Programmers/Lv2/압축_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class lv2_압축 {
public static void main(String[] args) {

String msg = "KAKAO";

//

ArrayList<String> alp = new ArrayList<>(Arrays.asList("1", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z"));

List<Integer> ans = new ArrayList<>();

outer: for(int i=0; i<msg.length(); i++) {
int idx = i+2;
while(idx<=msg.length()) {
if(alp.contains(msg.substring(i, idx))) {
idx++;
}else {
alp.add(msg.substring(i, idx));
//System.out.println(msg.substring(i, idx));
ans.add(alp.indexOf(msg.substring(i, idx-1)));
//System.out.println(msg.substring(i, idx-1));
i = idx-2;
//System.out.println(i);
break;
}
}
// 마지막부분 처리
if(idx>msg.length()) {
ans.add(alp.indexOf(msg.substring(i, msg.length())));
break outer;
}
}

// 정답 배열로 출력
int[] answer = new int[ans.size()];

for(int i=0; i<ans.size(); i++) {
answer[i] = ans.get(i);
}

System.out.println(Arrays.toString(answer));
}
}
22 changes: 22 additions & 0 deletions 0512/Programmers/Lv1/음양더하기_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

public class lv1_음양더하기 {
public static void main(String[] args) {

int[] absolutes = {4, 7, 12};
boolean[] signs = {true,false,true}; // true: 양수 false: 음수
int answer = 0;

//

for(int i=0; i<signs.length; i++) {
if(signs[i]) {
answer+= absolutes[i];
}else {
answer-= absolutes[i];
}
}

System.out.println(answer);
}

}