├── .github └── PULL_REQUEST_TEMPLATE │ └── pull_request_template.md ├── BOJ ├── 1012.유기농배추 │ ├── chan.java │ ├── haeun.java │ ├── oh.java │ └── readme.md ├── 10159. 저울 │ ├── ch_10159.java │ ├── chan_10159.java │ ├── haeun_10159.java │ ├── oh_10159.java │ └── readme.md ├── 10282. 해킹 │ ├── ch_10282.java │ ├── chan_10282.java │ ├── haeun_10282.java │ └── oh_10282.java ├── 1063. 킹 │ ├── README.md │ ├── chan_1063.java │ └── oh_1063.java ├── 10819. 차이를 최대로 │ ├── README.md │ ├── ch_10819.java │ ├── chan_10819.java │ ├── haeun_10819.java │ └── oh_10819.java ├── 10996. 별찍기-21 │ ├── haeun_10996.java │ ├── oh_10996.java │ └── readme.md ├── 1106.호텔 │ ├── ch_1106.java │ ├── chan_1106.java │ ├── haeun_1106.java │ └── readme.md ├── 1107. 리모컨 │ ├── README.md │ ├── ch_1107.java │ ├── chan_1107.java │ ├── haeun_1107.java │ └── oh_1107.java ├── 11399.ATM │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java ├── 11403. 경로찾기 │ ├── ch_11403.java │ ├── chan_11403.java │ ├── haeun_11403.java │ └── oh_11403.java ├── 11404. 플로이드 │ ├── ch_11404.java │ ├── chan_11404.java │ ├── haeun_11404.java │ └── oh_11404.java ├── 11657.타임머신 │ ├── ch_11657.java │ ├── chan_11657.java │ ├── haeun_11657.java │ ├── oh_11657.java │ └── readme.md ├── 1197. 최소 스패닝 트리 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java ├── 1238. 파티 │ ├── README.md │ ├── ch_1238.java │ ├── chan_1238.java │ └── oh_1238.java ├── 1245.농장관리 │ ├── README.md │ ├── ch_1245.java │ ├── chan_1245.java │ └── oh_1245.java ├── 1260. DFS와 BFS │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1261.algospot │ ├── ch_1261.java │ ├── haeun_1261.java │ ├── oh_1261_01BFS.java │ ├── oh_1261_Dij.java │ └── readme.md ├── 12847. 꿀아르바이트 │ └── README.md ├── 12865. 평범한 배낭 │ ├── README.md │ ├── ch_12865.java │ ├── chan_12865.java │ └── haeun_12865.java ├── 12891. DNA 비밀번호 │ ├── chan_12891.java │ ├── haeun_12891.java │ └── readme.md ├── 13424.비밀모임 │ ├── README.md │ ├── chan.java │ └── oh_13424.java ├── 1368.물대기 │ ├── README.md │ └── mj.java ├── 1389. 케빈 베이컨의 6단계 법칙 │ ├── chan_1389.java │ ├── haeun_1389.java │ └── oh_1389.java ├── 1446.지름길 │ ├── README.md │ ├── ch_1446.java │ ├── chan_1446.java │ └── oh_1446.java ├── 14465. 소가 길을 건너간 이유 5 │ ├── README.md │ ├── chan_14465.java │ ├── haeun_14465.java │ └── oh_14465.java ├── 14499.주사위굴리기 │ ├── README.md │ ├── chan_14499.java │ └── oh_14499.java ├── 14621. 나만 안되는 연애 │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java ├── 14696.딱지놀이 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java ├── 14719.빗물 │ ├── README.md │ ├── chan_14179.java │ └── oh_14719.java ├── 14728. 벼락치기 │ ├── README.md │ ├── ch_14728.java │ ├── chan_14728.java │ ├── haeun_14728.java │ └── oh_14728.java ├── 14888. 연산자 끼워넣기 │ ├── README.md │ ├── ch_14888.java │ ├── chan_14888.java │ ├── haeun_14888.java │ └── oh_14888.java ├── 14889. 스타트와 링크 │ ├── README.md │ ├── ch_14889.java │ ├── chan_14889.java │ └── haeun_14889.java ├── 14890.경사로 │ └── chan.java ├── 14938.서강그라운드 │ ├── chan_14938.java │ ├── oh_14938.java │ └── oh_14938_floyd.java ├── 1504. 특정한 최단 경로 │ ├── ch_1504.java │ ├── chan_1504.java │ ├── haeun_1504.java │ └── oh_1504.java ├── 1520. 내리막길 │ └── chan_1520.java ├── 1541. 잃어버린 괄호 │ └── ch_1541.java ├── 15662.톱니바퀴2 │ ├── README.md │ ├── chan.java │ └── oh_15662.java ├── 15683.감시 │ ├── README.md │ └── oh_15683.java ├── 15685.드래곤커브 │ ├── README.md │ └── chan.java ├── 16064. Coolest Ski Route │ ├── README.md │ ├── ch_16064_floyd.java │ ├── chan_16064.java │ ├── haeun_16064.java │ └── oh_16064_floyd.java ├── 16234. 인구이동 │ ├── Readme.md │ ├── ch_16234.java │ ├── chan_16234.java │ └── oh_16234.java ├── 16395. 파스칼의 삼각형 │ ├── ch.java │ ├── chan.java │ └── haeun.java ├── 1647. 도시 분할 계획 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java ├── 16918. 봄버맨 │ ├── ch_16918.java │ ├── chan_16918.java │ ├── oh_16918.java │ └── readme.md ├── 16922. 로마 숫자 만들기 │ ├── ch_16922.java │ ├── chan_16922.java │ ├── haeun_16922.java │ ├── oh_16922.java │ └── readme.md ├── 1707. 이분 그래프 │ ├── chan_1707.java │ ├── haeun_1707.java │ └── oh_1707.java ├── 17086.아기상어2 │ ├── README.md │ ├── ch_17086.java │ ├── chan_17086.java │ ├── mj_17086.java │ └── oh.17086.java ├── 17140.이차원배열과연산 │ ├── README.md │ └── chan.java ├── 17142. 연구소3 │ ├── ch_17142.java │ ├── chan_17142.java │ ├── oh_17142.java │ └── readme.md ├── 1719. 택배 │ ├── README.md │ ├── ch_1719.java │ └── chan_1719.java ├── 17208. 카우버거 알바생 │ └── README.md ├── 1738. 골목길 │ ├── ch_1738.java │ ├── chan_1738.java │ ├── haeun_1738.java │ └── readme.md ├── 1753.최단경로 │ ├── ch_1753.java │ ├── chan_1753.java │ ├── haeun_1753.java │ └── oh_1753.java ├── 1774.우주신과의교감 │ ├── README.md │ └── mj.java ├── 18223.민준이와마산그리고건우 │ ├── chan_18223.java │ └── oh_18223.java ├── 18405.경쟁적 전염 │ ├── mj_18405.java │ ├── oh_18405.java │ └── readme.md ├── 18428. 감시피하기 │ ├── ch_18428.java │ ├── haeun_18428.java │ ├── oh_18428.java │ └── readme.md ├── 1865. 웜홀 │ ├── README.md │ ├── ch_1865_bellman.java │ ├── chan_1865.java │ ├── haeun_1865.java │ ├── oh_1865_bellman.java │ └── oh_1865_floyd.java ├── 1890. 점프 │ └── readme.md ├── 1922. 네트워크연결 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java ├── 1941. 소문난 칠공주 │ ├── README.md │ └── chan_1941.java ├── 1946.신입사원 │ ├── chan_1946.java │ ├── mj_1946.java │ └── oh_1946.java ├── 1956. 운동 │ ├── ch_1956.java │ ├── chan_1956.java │ ├── haeun_1956.java │ └── oh_1956.java ├── 1967. 트리의 지름 │ ├── README.md │ ├── ch_1967.java │ ├── chan_1967.java │ ├── haeun_1967.java │ └── oh_1967.java ├── 20165.인내의도미노장인호석 │ ├── chan_20165.java │ └── oh_20165.java ├── 20437. 문자열 게임 2 │ ├── README.md │ ├── chan_20437.java │ └── haeun_20437.java ├── 20529. 가장 가까운 세사람의 심리적 거리 │ ├── ch_20529.java │ ├── chan_20529.java │ ├── haeun_20529.java │ ├── oh_20529.java │ └── read.md ├── 20546.기적의 매매법 │ └── chan.java ├── 2096. 내려가기 │ └── README.md ├── 21608.상어초등학교 │ ├── README.md │ └── chan.java ├── 21610. 마법사 상어와 비바라기 │ ├── oh_21610.java │ └── readme.md ├── 2178.미로탐색 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 21921. 블로그 │ ├── README.md │ ├── chan_21921.java │ ├── haeun_21921.java │ └── oh_21921.java ├── 2193. 이친수 │ ├── README.md │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 2217.로프 │ └── README.md ├── 22858.원상복구 │ ├── chan.java │ └── mj.java ├── 2292.벌집 │ ├── README.md │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh ├── 2343. 기타레슨 │ ├── ch_기타레슨.java │ ├── chan_2343.java │ ├── haeun_2343.java │ ├── oh_2343.java │ └── readme.md ├── 2460.지능형 기차2 │ ├── README.md │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh_2460.java ├── 2467. 용액 │ ├── README.md │ ├── ch_2467.java │ ├── chan_2467.java │ └── haeun_2467.java ├── 2468. 안전영역 │ ├── Readme.md │ ├── ch_2468.java │ ├── chan_2468.java │ ├── haeun_2468.java │ └── oh_2468.java ├── 2529. 부등호 │ ├── README.md │ ├── ch_2529.java │ ├── chan_2529.java │ ├── haeun_2529.java │ └── oh_2529.java ├── 2564.경비원 │ └── readme.md ├── 2573. 빙산 │ ├── README.md │ ├── ch_2573.java │ ├── chan_2573.java │ ├── haeun_2573.java │ └── oh_2573.java ├── 2579.계단오르기 │ ├── README.md │ ├── ch.java │ ├── chan.java │ └── haeun.java ├── 2589. 보물섬 │ ├── ch_2589.java │ ├── chan_2589.java │ ├── haeun_2589.java │ ├── oh_2589.java │ └── readme.md ├── 2606.바이러스 │ ├── README.md │ ├── haeun.java │ └── oh.java ├── 2631. 줄세우기 │ └── ch_2631.java ├── 2638. 치즈 │ ├── Readme.md │ ├── ch_2638.java │ └── chan_2638.java ├── 2644. 촌수계산 │ ├── README.md │ ├── ch_2644.java │ ├── chan_2644.java │ ├── haeun_2644.java │ └── oh_2644_floyd.java ├── 2665.미로만들기 │ ├── README.md │ ├── chan_2665.java │ ├── haeun_2665.java │ └── oh_2665.java ├── 2667. 단지번호붙이기 │ ├── README.md │ ├── ch_2667.java │ ├── chan_2667.java │ └── haeun_2667.java ├── 2671. 잠수함식별 │ ├── README.md │ ├── ch_2671.java │ ├── chan_2671.java │ ├── haeun_2671.java │ └── oh_2671.java ├── 2887.행성터널 │ └── README.md ├── 4781. 사탕가게 │ └── readme.md ├── 47821. 사탕가게 │ ├── ch_4781.java │ ├── chan_4781.java │ └── haeun_4781.java ├── 4963. 섬의 개수 │ ├── Readme.md │ ├── mj_4963 │ └── oh_4963.java ├── 5972. 택배배송 │ ├── Readme.md │ ├── ch_5972.java │ ├── chan_5972.java │ └── oh_5972.java ├── 6603.로또 │ ├── README.md │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh ├── 7562. 나이트의 이동 │ ├── Readme.md │ ├── ch_7562.java │ ├── chan_7562.java │ └── mj_7562.java ├── 7795. 먹을 것인가 먹힐 것인가 │ ├── README.md │ ├── ch_먹을것인가먹힐것인가.java │ ├── chan_7795.java │ ├── haeun_7795.java │ └── oh_7795.java ├── 8911. 거북이 │ ├── ch_8911.java │ ├── haeun_8911.java │ └── oh_8911.java ├── 9342. 염색체 │ ├── README.md │ ├── ch_9342.java │ ├── chan_9342.java │ ├── haeun_9342.java │ └── oh_9342.java ├── 9465. 스티커 └── 9996. 한국이 그리울 땐 서버에 접속하지 │ ├── ch_9996.java │ ├── chan_9996.java │ ├── haeun_9996.java │ ├── oh_9996.java │ └── readme.md ├── README.md ├── SWEA ├── 10505.소득 불균형 │ ├── Expert10505.java │ ├── chan.java │ ├── changhyun.java │ ├── haeun.java │ └── oh.java ├── 10912. 외로운 문자 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1206.View │ ├── chan.java │ ├── changhyun.java │ ├── haeun.java │ └── jamoon.java ├── 1209.Sum │ ├── chan.java │ ├── changhyun.java │ ├── haeun.java │ └── jaemoon.java ├── 1211.Ladder2 │ ├── Expert1211.java │ └── haeun.java ├── 1213.String │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1215.회문1 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1216.회문2 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1217.거듭제곱 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1219.길찾기 │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1221.GNS │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1222.계산기1 │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1224.계산기3 │ └── oh.java ├── 1226.미로1 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1227. 미로2 │ └── haeun.java ├── 1229. 암호문2 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1230. 암호문3 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1231.중위순회 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1232.사칙연산 │ ├── SWEA_D4_1232_사칙연산.java │ └── oh.java ├── 1234. 비밀번호 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1238. Contact │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1240. 단순 2진 암호코드 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 1244. 최대 상금 │ └── chan.java ├── 1251. 하나로 │ ├── ch.java │ ├── chan.java │ └── oh.java ├── 1263.사람 네트워크2 │ ├── chan_1263.java │ └── oh_1263.java ├── 1860. 진기의 최고급 붕어빵 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 2817.부분 수열의 합 │ ├── Expert2817.java │ ├── ch.java │ ├── chan.java │ └── haeun.java ├── 4192. 수영대회(완전탐색) │ ├── README.md │ ├── ch_4192.java │ ├── chan_4192.java │ ├── haeun_4192.java │ └── oh_4192.java ├── 5948.새샘이의 7-3-5 게임 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 6719. 성수의 프로그래밍 강좌 시청 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 7102.준홍이의 카드놀이 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── oh.java ├── 8016.홀수 피라미드 │ ├── chan.java │ ├── changHyun.java │ ├── haeun.java │ └── oh.java ├── 8382. 방향 전환 │ ├── README.md │ ├── ch_방향전환.java │ ├── chan_8382.java │ ├── haeun_8382.java │ └── oh_8382.java └── 8931.제로 │ ├── Expert8931.java │ ├── ch.java │ ├── chan.java │ └── haeun.java ├── THEORY └── DataStructure │ ├── PriorityQueue.md │ └── Set.md └── programmers ├── 2017 카카오코드 본선 └── 단체사진 찍기 │ ├── ch.java │ ├── chan.java │ └── mj.java ├── 2017 카카오코드 예선 └── 카카오프렌즈 컬러링북 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── mj.java ├── 2019 카카오 개발자 겨울 인턴십 └── 크레인 인형뽑기 게임 │ ├── ch_64061.java │ ├── chan.java │ └── mj.java ├── 2019KAKAO블라인드 └── 오픈채팅방 │ ├── ch_42888.java │ ├── chan.java │ ├── mj.java │ └── oh_오픈채팅.java ├── 2020 KAKAO BLIND RECRUITMENT ├── 괄호 변환 │ ├── README.md │ ├── chan.java │ └── mj.java ├── 문자열 압축 │ ├── README.md │ ├── ch_60057.java │ ├── chan_60057.java │ ├── mj_60057.java │ └── oh_문자열압축.java └── 실패율 │ └── ch_실패율.java ├── 2020 카카오 인턴십 └── 키패드 누르기 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── mj.java ├── 2021 Dev-Matching 웹 백엔드 개발 └── 행렬 테두리 회전하기 │ ├── chan.java │ └── mj.java ├── 2021 Dev-Matching ├── 로또의 최고 순위와 최저 순위 │ ├── README.md │ ├── ch_77484.java │ ├── chan.java │ ├── mj.java │ └── oh_로또.java └── 행렬 테두리 회전하기 │ └── chan.java ├── 2021 KAKAO BLIND RECRUITMENT ├── 메뉴리뉴얼 │ └── README.md └── 신규아이디추천 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ ├── oh_new_id_recommend.java │ └── readme.md ├── 2021 카카오 채용연계형 인턴십 ├── 거리두기 확인하기 │ └── chan.java └── 숫자 문자열과 영단어 │ ├── README.md │ ├── ch_숫자문자열과영단어.java │ ├── chan.java │ ├── haeun_숫자문자열과영단어.java │ ├── mj_숫자문자열과영단어.java │ └── oh_숫자_문자열과_영단어.java ├── 2022 KAKAO BLIND RECRUITMENT └── 신고 결과 받기 │ ├── README.md │ ├── ch_92334.java │ ├── chan_92334.java │ ├── mj_92334.java │ └── oh_신고결과받기.java ├── Summer,Winter Coding(2019) └── 멀쩡한 사각형 │ ├── README.md │ ├── ch.java │ ├── chan_62048.java │ └── mj.java ├── Summer,Winter Coding(~2018) ├── 배달 │ ├── chan.java │ └── oh_dij.java └── 소수만들기 │ ├── chan.java │ └── mj.java ├── 스택큐 ├── 기능개발 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ ├── mj.java │ └── oh.java └── 프린터 │ └── ch_프린터.java ├── 월간코드챌린지시즌1 └── 내적 │ ├── chan.java │ └── mj.java ├── 월간코드챌린지시즌2 ├── 약수의 개수와 덧셈 │ └── ch_약수의개수와덧셈.java └── 음양더하기 │ ├── chan.java │ └── mj.java ├── 월간코드챌린지시즌3 └── 없는숫자더하기 │ ├── README.md │ ├── ch.java │ ├── chan.java │ └── mj.java ├── 찾아라 프로그래밍 마에스터 ├── README.md ├── mj.java └── 폰켓몬 │ └── chan.java └── 코딩테스트연습 ├── 124 나라의 숫자 ├── ch_12899.java ├── chan.java └── mj.java ├── 2017팁스타운 └── 짝지어제거하기 │ ├── README.md │ ├── chan.java │ └── mj.java ├── 완전탐색 ├── 모의고사 │ ├── ch.java │ ├── chan.java │ └── mj.java └── 카펫 │ ├── ch.java │ ├── chan.java │ ├── haeun.java │ └── ohj.java ├── 이분탐색 └── 입국심사 │ ├── ch_입국심사.java │ ├── chan.java │ ├── haeun_입국심사.java │ ├── oh_입국심사.java │ └── readme.md ├── 정렬 └── K번째수 │ ├── README.md │ └── mj.java ├── 탐욕법(Greedy) └── 체육복 │ ├── README.md │ ├── ch.java │ ├── chan.java │ └── mj.java ├── 해시 ├── 42576. 완주하지못한 선수 │ ├── ch_완주하지못한선수.java │ ├── chan_42576.java │ ├── haeun_완주하지못한선수.java │ ├── mj.java │ ├── oh.java │ └── readme.md ├── 42577. 전화번호 목록 │ ├── README.md │ ├── ch_전화번호목록.java │ ├── chan_42577.java │ ├── haeun_전화번호목록.java │ └── oh.java ├── 42578.위장 │ ├── ch_위장.java │ ├── chan_42578.java │ ├── haeun_위장.java │ ├── oh.java │ └── readme.md └── 42579. 베스트앨범 │ ├── README.md │ ├── ch_베스트앨범.java │ ├── chan_42579.java │ ├── haeun_42579.java │ └── oh_베스트앨범.java └── 힙(heap) ├── readme.md └── 더 맵게 ├── ch_42626.java ├── mj.java └── oh.java /.github/PULL_REQUEST_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### **📚** 무엇에 관한 것인가요? 2 | 3 | 4 | ### **📋** 어떤 어려움이 있었나요? 5 | 6 | 7 | ### **🎲** 어떻게 해결하였나요? 8 | -------------------------------------------------------------------------------- /BOJ/1012.유기농배추/readme.md: -------------------------------------------------------------------------------- 1 | [백준 -1012.유기농배추 2 | ](https://www.acmicpc.net/problem/1012) 3 | 4 | -------------------------------------------------------------------------------- /BOJ/10159. 저울/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 10159. 저울](https://www.acmicpc.net/problem/10159) 2 | -------------------------------------------------------------------------------- /BOJ/1063. 킹/README.md: -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/1063 2 | -------------------------------------------------------------------------------- /BOJ/10819. 차이를 최대로/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 10819. 차이를 최대로](https://www.acmicpc.net/problem/10819) -------------------------------------------------------------------------------- /BOJ/10819. 차이를 최대로/haeun_10819.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_10819_차이를최대로 { 7 | 8 | public static int N, max; 9 | public static int[] A, arr; 10 | public static boolean[] checked; 11 | 12 | public static void main(String[] args) throws IOException { 13 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 14 | N = Integer.parseInt(br.readLine()); // N개의 정수 15 | A = new int[N]; // 입력받는 배열 16 | arr = new int[N]; 17 | checked = new boolean[N]; 18 | 19 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 20 | // 배열 채우기 21 | for (int i = 0; i < N; i++) { 22 | A[i] = Integer.parseInt(st.nextToken()); 23 | } 24 | // 최댓값을 최소로 초기화 25 | max = Integer.MIN_VALUE; 26 | 27 | perm(0); 28 | // 출력 29 | System.out.println(max); 30 | } 31 | 32 | // 순열 33 | public static void perm(int num) { 34 | // 기저조건 35 | if (num == N) { 36 | // 주어진 식대로 계산 37 | int sum = 0; 38 | for (int i = 0; i < N-1; i++) { 39 | sum += Math.abs(arr[i] - arr[i+1]); 40 | } 41 | // 최댓값 갱신 42 | if (sum > max) max = sum; 43 | return; 44 | } 45 | 46 | for (int i = 0; i < N; i++) { 47 | if (checked[i]) continue; 48 | arr[num] = A[i]; 49 | checked[i] = true; 50 | perm(num + 1); 51 | checked[i] = false; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /BOJ/10996. 별찍기-21/haeun_10996.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BOJ_10996_별찍기21 { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int cnt = n / 2; 9 | 10 | // N번만큼 반복 11 | for (int i = 0; i < n; i++) { 12 | // 윗줄 13 | int up; 14 | // N이 짝수일때, 홀수일때 윗줄이 다름 15 | if (n % 2 == 0) up = cnt; 16 | else up = cnt + 1; 17 | while (up-- > 0) System.out.print("* "); 18 | System.out.println(); 19 | 20 | // 아랫줄 21 | int down = cnt; 22 | while (down-- > 0) System.out.print(" *"); 23 | System.out.println(); 24 | } 25 | sc.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BOJ/10996. 별찍기-21/oh_10996.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class oh_10996 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 10 | StringBuilder sb1 = new StringBuilder(); 11 | StringBuilder sb2 = new StringBuilder(); 12 | 13 | 14 | int num = Integer.parseInt(br.readLine()); 15 | for (int i = 0; i < num/2; i++) { 16 | sb1.append("* "); 17 | sb2.append("* "); 18 | } 19 | if(num%2!=0) { 20 | sb1.append("*"); 21 | } 22 | 23 | 24 | for (int i = 0; i < num; i++) { 25 | System.out.println(sb1); 26 | System.out.println(" "+sb2); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BOJ/10996. 별찍기-21/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 10996. 별찍기-21 2 | ](https://www.acmicpc.net/problem/10996) 3 | -------------------------------------------------------------------------------- /BOJ/1106.호텔/ch_1106.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class ch_1106 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine()); 11 | final int INF = 987654321; 12 | 13 | int C = Integer.parseInt(st.nextToken()); 14 | int N = Integer.parseInt(st.nextToken()); 15 | 16 | int[] cost = new int[N + 1]; 17 | int[] customer = new int[N + 1]; 18 | int[] DP = new int[C + 101]; 19 | Arrays.fill(DP, INF); 20 | DP[0] = 0; 21 | 22 | for (int i = 1; i <= N; i++) { 23 | st = new StringTokenizer(br.readLine()); 24 | cost[i] = Integer.parseInt(st.nextToken()); 25 | customer[i] = Integer.parseInt(st.nextToken()); 26 | } 27 | 28 | for (int i = 1; i <= N; i++) { 29 | for (int j = customer[i]; j < C + 101; j++) { 30 | DP[j] = Math.min(DP[j], cost[i] + DP[j - customer[i]]); 31 | } 32 | } 33 | 34 | int min = INF; 35 | for (int i = C; i < C + 101; i++) { 36 | min = Math.min(min, DP[i]); 37 | } 38 | 39 | System.out.println(min); 40 | } 41 | } -------------------------------------------------------------------------------- /BOJ/1106.호텔/haeun_1106.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class BOJ_1106_호텔 { 8 | 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 12 | int C = Integer.parseInt(st.nextToken()); // 최소 C명 13 | int N = Integer.parseInt(st.nextToken()); // 도시의 개수 14 | int INF = 987654321; 15 | 16 | int[] dp = new int[C+101]; // 최소 비용 17 | Arrays.fill(dp, INF); 18 | dp[0] = 0; 19 | 20 | // dp 21 | for (int i = 0; i < N; i++) { 22 | st = new StringTokenizer(br.readLine(), " "); 23 | int cost = Integer.parseInt(st.nextToken()); // 홍보비용 24 | int customer = Integer.parseInt(st.nextToken());// 얻을 수 있는 고객의 수 25 | 26 | for (int j = customer; j < C + 101; j++) { 27 | dp[j] = Math.min(dp[j], cost + dp[j - customer]); 28 | } 29 | } 30 | 31 | // 최솟값 갱신 32 | int answer = INF; 33 | for (int i = C; i < C + 101; i++) { 34 | answer = Math.min(answer, dp[i]); 35 | } 36 | 37 | // 출력 38 | System.out.println(answer); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /BOJ/1106.호텔/readme.md: -------------------------------------------------------------------------------- 1 | [1106.호텔](https://www.acmicpc.net/problem/1106) 2 | -------------------------------------------------------------------------------- /BOJ/1107. 리모컨/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 1107. 리모컨](https://www.acmicpc.net/problem/1107) 2 | -------------------------------------------------------------------------------- /BOJ/11399.ATM/ch.java: -------------------------------------------------------------------------------- 1 | package BOJ; 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.StringTokenizer; 8 | 9 | public class BOJ_S3_11399_ATM { 10 | public static void main(String[] args) throws IOException { 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | StringTokenizer st = null; 13 | 14 | int T = Integer.parseInt(br.readLine()); 15 | int[] P = new int[T]; 16 | st = new StringTokenizer(br.readLine()); 17 | for (int t = 0; t < T; t++) { 18 | P[t] = Integer.parseInt(st.nextToken()); 19 | } 20 | Arrays.sort(P); 21 | int sum = 0; 22 | for (int i = 0; i < P.length; i++) { 23 | sum += (P.length - i) * P[i]; 24 | } 25 | System.out.println(sum); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BOJ/11399.ATM/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.Arrays; 4 | import java.util.StringTokenizer; 5 | 6 | public class chan { 7 | 8 | public static void main(String[] args) throws Exception { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int N = Integer.parseInt(br.readLine()); 11 | int ans = 0; 12 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 13 | int[] parr = new int[N]; 14 | for (int i = 0; i < N; i++) { 15 | parr[i] = Integer.parseInt(st.nextToken()); 16 | } 17 | // 입력 받기 완료 18 | 19 | // 필요한 시간의 합의 최소는 오름차순 정렬 20 | Arrays.sort(parr); 21 | 22 | // 걸리는 시간의 합 구하기 23 | for (int i = 0; i < N; i++) { 24 | for (int j = 0; j <= i; j++) { 25 | ans += parr[j]; 26 | } 27 | } 28 | System.out.println(ans); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /BOJ/11399.ATM/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class BOJ_11399_ATM { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int N = Integer.parseInt(br.readLine()); // 사람의 수 11 | 12 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 13 | int[] people = new int[N]; 14 | for (int i = 0; i < N; i++) { 15 | people[i] = Integer.parseInt(st.nextToken()); 16 | } 17 | 18 | // 오름차순으로 정렬 19 | Arrays.sort(people); 20 | // 인출하는 시간의 합 구하기 21 | int sum = 0; 22 | for (int i = 0; i < N; i++) { 23 | if (i > 0) { 24 | for (int j = 0; j < i; j++) { 25 | sum += people[j]; 26 | } 27 | } 28 | sum += people[i]; 29 | } 30 | // 출력 31 | System.out.println(sum); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /BOJ/11399.ATM/mj.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class W_11399_ATM { 8 | 9 | public static void main(String[] args) throws IOException { 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[] P = new int[N]; 15 | st = new StringTokenizer(br.readLine()); 16 | for (int i = 0; i < N; i++) { 17 | P[i] = Integer.parseInt(st.nextToken()); 18 | } 19 | 20 | Arrays.sort(P); 21 | int[] sum = new int[N]; 22 | sum[0] = P[0]; 23 | for (int i = 1; i < N; i++) { 24 | sum[i] = sum[i-1]+P[i]; 25 | } 26 | 27 | int ans = 0; 28 | for (int i = 0; i < N; i++) { 29 | ans += sum[i]; 30 | } 31 | 32 | System.out.println(ans); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BOJ/11399.ATM/oh.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class BOJ11399 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 10 | int T = Integer.parseInt(br.readLine()); 11 | int[] arr = new int[T]; 12 | StringTokenizer st = new StringTokenizer(br.readLine()); 13 | for (int i = 0; i < arr.length; i++) { 14 | arr[i]=Integer.parseInt(st.nextToken()); 15 | } 16 | Arrays.sort(arr); 17 | int sum =0; 18 | int answer =0; 19 | for (int i : arr) { 20 | sum+=i; 21 | answer+=sum; 22 | } 23 | System.out.println(answer); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BOJ/11403. 경로찾기/chan_11403.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | public class chan_11403 { 6 | 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int N = Integer.parseInt(br.readLine()); 10 | int[][] map = new int[N][N]; 11 | final int INF = 987654321; 12 | for (int i = 0; i < N; i++) { 13 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 14 | for (int j = 0; j < N; j++) { 15 | map[i][j] = Integer.parseInt(st.nextToken()); 16 | if (map[i][j] == 0) map[i][j] = INF; 17 | } 18 | } 19 | 20 | /* 플로이드 와샬 */ 21 | for (int k = 0; k < N; k++) { 22 | for (int i = 0; i < N; i++) { 23 | for (int j = 0; j < N; j++) { 24 | map[i][j] = Math.min(map[i][j], map[i][k] + map[k][j]); 25 | } 26 | } 27 | } 28 | 29 | for (int i = 0; i < N; i++) { 30 | for (int j = 0; j < N; j++) { 31 | if (map[i][j] == INF) map[i][j] = 0; 32 | else map[i][j] = 1; 33 | System.out.print(map[i][j] + " "); 34 | } 35 | System.out.println(); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /BOJ/11403. 경로찾기/haeun_11403.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_11403_경로찾기 { 7 | 8 | public static void main(String[] args) throws IOException{ 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int N = Integer.parseInt(br.readLine()); // 정점의 개수 11 | int[][] arr = new int[N][N]; // 인접 행렬 12 | 13 | // 인접 행렬 입력 받기 14 | for (int i = 0; i < N; i++) { 15 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 16 | for (int j = 0; j < N; j++) { 17 | arr[i][j] = Integer.parseInt(st.nextToken()); 18 | } 19 | } 20 | 21 | // 플로이드-와샬 22 | // 경유지 23 | for (int k = 0; k < N; k++) { 24 | // 출발 25 | for (int i = 0; i < N; i++) { 26 | // 도착 27 | for (int j = 0; j < N; j++) { 28 | // 경로가 있다면 29 | if (arr[i][k] == 1 && arr[k][j] == 1) { 30 | arr[i][j] = 1; 31 | } 32 | } 33 | } 34 | } 35 | 36 | // 출력 37 | for (int i = 0; i < N; i++) { 38 | for (int j = 0; j < N; j++) { 39 | System.out.print(arr[i][j]+" "); 40 | } 41 | System.out.println(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /BOJ/11657.타임머신/readme.md: -------------------------------------------------------------------------------- 1 | [11657.🚀](https://boj.kr/11657) 2 | 3 | 시간은 과거에서 현재로, 현재에서 미래로만 향한다는 뜻이다. 아직까지 시간이 미래에서 현재로, 현재에서 과거로 역류한 예는 없었다. 따라서 어떤 기계를 만들더라도 이러한 시간의 비가역성을 바꾸어놓을 수 없으므로 타임머신은 불가능하다 4 | -------------------------------------------------------------------------------- /BOJ/1238. 파티/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1238. 파티](https://www.acmicpc.net/problem/1238) 2 | -------------------------------------------------------------------------------- /BOJ/1245.농장관리/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1245. 농장 관리](https://www.acmicpc.net/problem/1245) 2 | -------------------------------------------------------------------------------- /BOJ/1261.algospot/readme.md: -------------------------------------------------------------------------------- 1 | [![image](https://user-images.githubusercontent.com/51963264/140062674-e8638b13-2dc6-4b1a-af4a-48bfff929ab7.png)](https://www.acmicpc.net/problem/1261) 2 | 3 |
4 | 알고스팟은 수많은 패키지들과 서버들이 합쳐져 돌아가고 있다. 5 | 따라서 이들을 각각 개인 서버에 셋업해 개발하는 것보다는, 가상머신을 이용하고 가상머신을 쉽게 셋업해 줄 수 있는 도구를 이용하기로 하자. 알고스팟의 공식 개발 환경은 vagrant를 이용한다. 6 | vagrant는 VirtualBox, VMWare 등의 가상화 도구를 커맨드 라인에서 사용하기 쉽게 포장해 둔 것이다. 7 |
8 | -------------------------------------------------------------------------------- /BOJ/12847. 꿀아르바이트/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 12847. 꿀아르바이트](https://www.acmicpc.net/problem/12847) 2 | -------------------------------------------------------------------------------- /BOJ/12865. 평범한 배낭/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 12865. 평범한 배낭](https://www.acmicpc.net/problem/12865) 2 | -------------------------------------------------------------------------------- /BOJ/12865. 평범한 배낭/ch_12865.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class ch_12865 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = new StringTokenizer(br.readLine()); 10 | 11 | int N = Integer.parseInt(st.nextToken()); 12 | int K = Integer.parseInt(st.nextToken()); 13 | 14 | int[] weight = new int[N + 1]; 15 | int[] value = new int[N + 1]; 16 | int[][] DP = new int[N+1][K+1]; 17 | 18 | for (int i = 1; i <= N; i++) { 19 | st = new StringTokenizer(br.readLine()); 20 | weight[i] = Integer.parseInt(st.nextToken()); 21 | value[i] = Integer.parseInt(st.nextToken()); 22 | } 23 | 24 | for (int i = 1; i <= N; i++) { 25 | for (int j = 1; j <= K; j++) { 26 | if (weight[i] <= j){ 27 | DP[i][j] = Math.max(DP[i - 1][j], value[i] + DP[i - 1][j - weight[i]]); 28 | }else { 29 | DP[i][j] = DP[i-1][j]; 30 | } 31 | } 32 | } 33 | 34 | System.out.println(DP[N][K]); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BOJ/12865. 평범한 배낭/chan_12865.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | public class chan_12865 { 6 | 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 10 | int N = Integer.parseInt(st.nextToken()); 11 | int K = Integer.parseInt(st.nextToken()); 12 | 13 | int[] weights = new int[N + 1]; 14 | int[] profits = new int[N + 1]; 15 | for (int i = 1; i <= N; i++) { 16 | st = new StringTokenizer(br.readLine(), " "); 17 | weights[i] = Integer.parseInt(st.nextToken()); 18 | profits[i] = Integer.parseInt(st.nextToken()); 19 | } 20 | 21 | int[] D = new int[K + 1]; 22 | for (int i = 1; i <= N; i++) { 23 | for (int k = K; k >= weights[i]; k--) 24 | D[k] = Math.max(D[k], profits[i] + D[k - weights[i]]); 25 | } 26 | 27 | System.out.println(D[K]); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /BOJ/12865. 평범한 배낭/haeun_12865.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_12865_배낭 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 11 | 12 | int N = Integer.parseInt(st.nextToken()); // 물품의 수 13 | int K = Integer.parseInt(st.nextToken()); // 버틸 수 있는 무게 14 | 15 | int[] weight = new int[N+1]; // 물건의 무게 16 | int[] value = new int[N+1]; // 해당 물건의 가치 17 | int[][] dp = new int[N+1][K+1]; 18 | 19 | for(int i = 1; i <= N; i++) { 20 | st = new StringTokenizer(br.readLine(), " "); 21 | weight[i] = Integer.parseInt(st.nextToken()); 22 | value[i] = Integer.parseInt(st.nextToken()); 23 | } 24 | 25 | // dp 26 | for (int i = 1; i <= N; i++) { 27 | for (int j = 1; j <= K; j++) { 28 | // 해당 물건을 가방에 넣을 수 없다. 29 | if (weight[i] > j) dp[i][j] = dp[i-1][j]; 30 | // 해당 물건을 가방에 넣을 수 있다. 31 | else dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-weight[i]]+value[i]); 32 | } 33 | } 34 | 35 | // 출력 36 | System.out.println(dp[N][K]); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /BOJ/12891. DNA 비밀번호/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 12891. DNA 비밀번호](https://www.acmicpc.net/problem/12891) 2 | -------------------------------------------------------------------------------- /BOJ/13424.비밀모임/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 13424.비밀모임](https://www.acmicpc.net/problem/13424) 2 | -------------------------------------------------------------------------------- /BOJ/1368.물대기/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1368. 물대기](https://www.acmicpc.net/problem/1368) -------------------------------------------------------------------------------- /BOJ/1446.지름길/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1446.지름길](https://www.acmicpc.net/problem/1446) 2 | -------------------------------------------------------------------------------- /BOJ/14465. 소가 길을 건너간 이유 5/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 14465. 소가 길을 건너간 이유 5](https://www.acmicpc.net/problem/14465) 2 | -------------------------------------------------------------------------------- /BOJ/14465. 소가 길을 건너간 이유 5/haeun_14465.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_14465_소가길을건너간이유5 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 11 | 12 | int N = Integer.parseInt(st.nextToken()); // 횡단보도 N개 13 | int K = Integer.parseInt(st.nextToken()); // 연속한 K개 신호등 14 | int B = Integer.parseInt(st.nextToken()); // 고장난 신호등 개수 15 | 16 | // 고장난 신호등 17 | boolean[] light = new boolean[N+1]; 18 | int cnt = 0; 19 | 20 | for (int i = 0; i < B; i++) { 21 | int num = Integer.parseInt(br.readLine()); 22 | light[num] = true; 23 | if (num <= K) cnt++; 24 | } 25 | 26 | // 최솟값 27 | int min = cnt; 28 | // 투포인터 위치 29 | int left = 1; 30 | int right = K; 31 | 32 | // 투포인터 33 | while (right < N) { 34 | if (!light[left] && light[right+1]) cnt++; 35 | else if (light[left] && !light[right+1]) cnt--; 36 | 37 | // 최솟값 갱신 38 | if (cnt < min) min = cnt; 39 | 40 | // 포인터 이동 41 | left++; 42 | right++; 43 | } 44 | 45 | // 출력 46 | System.out.println(min); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /BOJ/14499.주사위굴리기/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 14499. 주사위 굴리기](https://www.acmicpc.net/problem/14499) 2 | -------------------------------------------------------------------------------- /BOJ/14719.빗물/README.md: -------------------------------------------------------------------------------- 1 | [BOJ_14719_빗물](https://www.acmicpc.net/problem/14719) 2 | -------------------------------------------------------------------------------- /BOJ/14728. 벼락치기/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 14728. 벼락치기](https://www.acmicpc.net/problem/14728) 2 | -------------------------------------------------------------------------------- /BOJ/14728. 벼락치기/ch_14728.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class ch_14728 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = new StringTokenizer(br.readLine()); 10 | 11 | int N = Integer.parseInt(st.nextToken()); 12 | int T = Integer.parseInt(st.nextToken()); 13 | 14 | int[] K = new int[N + 1]; 15 | int[] S = new int[N + 1]; 16 | int[][] DP = new int[N+1][T+1]; 17 | 18 | for (int i = 1; i <= N; i++) { 19 | st = new StringTokenizer(br.readLine()); 20 | K[i] = Integer.parseInt(st.nextToken()); 21 | S[i] = Integer.parseInt(st.nextToken()); 22 | } 23 | 24 | for (int i = 1; i <= N; i++) { 25 | for (int j = 1; j <= T; j++) { 26 | if (K[i] <= j){ 27 | DP[i][j] = Math.max(DP[i - 1][j], S[i] + DP[i - 1][j - K[i]]); 28 | }else { 29 | DP[i][j] = DP[i-1][j]; 30 | } 31 | } 32 | } 33 | 34 | System.out.println(DP[N][T]); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BOJ/14728. 벼락치기/chan_14728.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | public class chan_14728 { 6 | 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 10 | int N = Integer.parseInt(st.nextToken()); // 이번 시험의 단원 개수 11 | int T = Integer.parseInt(st.nextToken()); // 시험까지 공부 할 수 있는 총 시간 12 | 13 | int[] time = new int[N + 1]; 14 | int[] score = new int[N + 1]; 15 | 16 | for (int n = 1; n <= N; n++) { 17 | st = new StringTokenizer(br.readLine(), " "); 18 | time[n] = Integer.parseInt(st.nextToken()); //각 단원 별 예상 공부 시간 19 | score[n] = Integer.parseInt(st.nextToken()); // 그 단원 문제의 배점 20 | } 21 | 22 | int[] D = new int[T + 1]; 23 | 24 | for (int i = 1; i <= N; i++) { 25 | for (int t = T; t >= time[i]; t--) 26 | D[t] = Math.max(D[t], score[i] + D[t - time[i]]); 27 | } 28 | 29 | System.out.println(D[T]); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /BOJ/14728. 벼락치기/haeun_14728.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_14728_벼락치기 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 11 | int N = Integer.parseInt(st.nextToken()); // 단원 개수 12 | int T = Integer.parseInt(st.nextToken()); // 공부할 수 있는 총 시간 13 | 14 | int[] K = new int[N+1]; // 단원별 예상 공부 시간 15 | int[] S = new int[N+1]; // 단원 문제의 배점 16 | int[][] dp = new int[N+1][T+1]; 17 | 18 | for (int i = 1; i <= N; i++) { 19 | st = new StringTokenizer(br.readLine(), " "); 20 | K[i] = Integer.parseInt(st.nextToken()); 21 | S[i] = Integer.parseInt(st.nextToken()); 22 | } 23 | 24 | // dp 25 | for (int i = 1; i <= N; i++) { 26 | for (int j = 1; j <= T; j++) { 27 | // 해당 단원을 공부할 수 없다. 28 | if (K[i] > j) dp[i][j] = dp[i-1][j]; 29 | // 해당 단원을 공부할 수 있다. 30 | else dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-K[i]]+S[i]); 31 | } 32 | } 33 | 34 | // 출력 35 | System.out.println(dp[N][T]); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /BOJ/14728. 벼락치기/oh_14728.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | public class oh_14728 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine()); 11 | int n =Integer.parseInt(st.nextToken()); 12 | int t =Integer.parseInt(st.nextToken()); 13 | int[][] dp = new int[n + 1][t + 1]; 14 | 15 | int[] k = new int[n+1]; 16 | int[] s = new int[n+1]; 17 | 18 | for (int i = 1; i <= n; i++) { 19 | st = new StringTokenizer(br.readLine()); 20 | k[i]=Integer.parseInt(st.nextToken()); 21 | s[i]=Integer.parseInt(st.nextToken()); 22 | } 23 | for (int i = 1; i < dp.length; i++) { 24 | for (int j = 0; j < dp[i].length; j++) { 25 | if(j>=k[i]){ 26 | dp[i][j]=Math.max(s[i]+dp[i-1][j-k[i]],dp[i-1][j]); 27 | }else{ 28 | dp[i][j]=dp[i-1][j]; 29 | 30 | } 31 | } 32 | } 33 | System.out.println(dp[n][t]); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /BOJ/14888. 연산자 끼워넣기/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 14888. 연산자 끼워넣기](https://www.acmicpc.net/problem/14888) 2 | -------------------------------------------------------------------------------- /BOJ/14889. 스타트와 링크/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 14889. 스타트와 링크](https://www.acmicpc.net/problem/14889) 2 | -------------------------------------------------------------------------------- /BOJ/1541. 잃어버린 괄호/ch_1541.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | /*** 7 | * 최대한 큰 수를 빼야한다. 8 | * 덧셈 먼저 계산 후 빼기 9 | */ 10 | public class ch_1541 { 11 | public static void main(String[] args) throws IOException { 12 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | StringTokenizer st = new StringTokenizer(br.readLine(), "-"); 14 | 15 | int sum = Integer.MAX_VALUE; 16 | 17 | while (st.hasMoreTokens()){ 18 | int temp = 0; 19 | 20 | StringTokenizer add = new StringTokenizer(st.nextToken(), "+"); 21 | 22 | while (add.hasMoreTokens()){ 23 | temp += Integer.parseInt(add.nextToken()); 24 | } 25 | 26 | // 첫 번째 수 판별 27 | sum = (sum == Integer.MAX_VALUE) ? temp : sum - temp; 28 | } 29 | System.out.println(sum); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BOJ/15662.톱니바퀴2/README.md: -------------------------------------------------------------------------------- 1 | [BOJ_15662_톱니바퀴2](https://www.acmicpc.net/problem/15662) 2 | -------------------------------------------------------------------------------- /BOJ/15683.감시/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 15683. 감시](https://www.acmicpc.net/problem/15683) 2 | -------------------------------------------------------------------------------- /BOJ/15685.드래곤커브/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 15685. 드래곤 커브](https://www.acmicpc.net/problem/15685) 2 | -------------------------------------------------------------------------------- /BOJ/16064. Coolest Ski Route/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 16064. Coolest Ski Route](https://www.acmicpc.net/problem/16064) 2 | 3 | A ski is a narrow strip of semi-rigid material worn underfoot to glide over snow. Substantially longer than wide and characteristically employed in pairs, skis are attached to ski boots with ski bindings, with either a free, lockable, or partially secured heel. For climbing slopes, ski skins (originally made of seal fur, but now made of synthetic materials) can be attached at the base of the ski. 4 | -------------------------------------------------------------------------------- /BOJ/16234. 인구이동/Readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 16234. 인구이동](https://www.acmicpc.net/problem/16234) 2 | -------------------------------------------------------------------------------- /BOJ/16395. 파스칼의 삼각형/ch.java: -------------------------------------------------------------------------------- 1 | package BOJ; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.StringTokenizer; 7 | 8 | public class BOJ_16395_파스칼의삼각형 { 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | StringTokenizer st = new StringTokenizer(br.readLine()); 12 | int N = Integer.parseInt(st.nextToken()); 13 | int K = Integer.parseInt(st.nextToken()); 14 | 15 | int[][] dp = new int[31][31]; 16 | 17 | dp[1][1] = 1; 18 | dp[2][1] = 1; 19 | dp[2][2] = 1; 20 | 21 | for (int i = 3; i < N + 1; i++) { 22 | for (int j = 1; j < i + 1; j++) { 23 | if (j == 1 || j == i) dp[i][j] = 1; 24 | else dp[i][j] = dp[i-1][j-1] + dp[i-1][j]; 25 | } 26 | } 27 | System.out.println(dp[N][K]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BOJ/16395. 파스칼의 삼각형/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | /** 5 | * 요구사항 : 정수 N과 K가 주어졌을 때, 파스칼의 삼각형에 있는 N번째 행에서 K번째 수를 구해라 6 | * 제한 : 1 <= K <= N <= 30 7 | * 8 | * 파스칼의 삼각형 9 | * - 1. N번째 행에는 N개의 수가 있다. 10 | * - 2. 첫번째 행은 1이다. 11 | * - 3. 두번째 행부터 각 행의 양 끝의 값은 1이고, 나머지 수의 값은 바로 위 행의 인접한 두 수의 합이다. 12 | * 13 | * 점화식 14 | * - dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] 15 | * - 바로 위 행의 인접한 두 수의 합이 현재 행의 값이다. 16 | * - 조건 처리 : 각 행의 양 끝 값 1로 초기화하기 17 | * 18 | */ 19 | public class chan { 20 | 21 | public static void main(String[] args) throws Exception { 22 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 23 | String[] data = br.readLine().split(" "); 24 | int N = Integer.parseInt(data[0]); 25 | int K = Integer.parseInt(data[1]); 26 | int[][] dp = new int[31][31]; 27 | 28 | dp[1][1] = dp[2][1] = dp[2][2] = 1; 29 | 30 | for (int i = 3; i <= N; i++) { 31 | dp[i][1] = dp[i][i] = 1; 32 | for (int j = 2; j < i; j++) { 33 | dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; 34 | } 35 | } 36 | System.out.println(dp[N][K]); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /BOJ/16395. 파스칼의 삼각형/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_16395_파스칼의삼각형 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 10 | int n = Integer.parseInt(st.nextToken()); // n번째 행 11 | int k = Integer.parseInt(st.nextToken()); // k번째 수 12 | int[][] arr = new int[n+1][n+1]; 13 | 14 | arr[0][0] = 1; 15 | for (int i = 1; i < n+1; i++) { 16 | for (int j = 1; j < i+1; j++) { 17 | if (i == 0 || i == j) arr[i][j] = 1; 18 | else arr[i][j] = arr[i-1][j-1] + arr[i-1][j]; 19 | } 20 | } 21 | 22 | // 출력 23 | System.out.println(arr[n][k]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BOJ/16918. 봄버맨/readme.md: -------------------------------------------------------------------------------- 1 | [16918.봄버맨](https://www.acmicpc.net/problem/16918) 2 | -------------------------------------------------------------------------------- /BOJ/16922. 로마 숫자 만들기/ch_16922.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class ch_16922 { 6 | static int N; 7 | static int[] number = {1, 5, 10, 50}; 8 | static boolean[] visited; 9 | static int[] answer; 10 | static int ans; 11 | public static void main(String[] args) throws IOException { 12 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | 14 | N = Integer.parseInt(br.readLine()); 15 | 16 | visited = new boolean[10000]; 17 | answer = new int[N]; 18 | solve(0, 0); 19 | System.out.println(ans); 20 | } 21 | 22 | private static void solve(int cnt, int start) { 23 | if (cnt == N){ 24 | int sum = 0; 25 | for (int i = 0; i < N; i++) { 26 | sum += answer[i]; 27 | } 28 | 29 | // 같은 값인지 체크 30 | if(!visited[sum]) { 31 | ans++; 32 | visited[sum] = true; 33 | } 34 | return; 35 | } 36 | for (int i = start; i < number.length; i++) { 37 | answer[cnt] = number[i]; 38 | solve(cnt + 1, i); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /BOJ/16922. 로마 숫자 만들기/haeun_16922.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Scanner; 3 | 4 | public class BOJ_16922_로마숫자만들기 { 5 | 6 | public static int N, count; 7 | public static int[] text, arr; 8 | public static HashSet hs; // 만들 수 있는 수 중복 체크 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | N = sc.nextInt(); // 사용할 수 있는 문자의 개수 13 | text = new int[] {1, 5, 10, 50}; // 로마 숫자 {'I', 'V', 'X', 'L'} 14 | arr = new int[N]; 15 | hs = new HashSet<>(); 16 | count = 0; 17 | 18 | comb(0, 0); 19 | 20 | // 출력 21 | System.out.println(count); 22 | sc.close(); 23 | } 24 | 25 | // 중복조합 26 | public static void comb(int num, int start) { 27 | // 기저조건 28 | if (num == N) { 29 | // 합계 구하기 30 | int sum = 0; 31 | for (int i = 0; i < N; i++) { 32 | sum += arr[i]; 33 | } 34 | // 중복되지 않는 수라면 count+1 35 | if (hs.add(sum)) count++; 36 | return; 37 | } 38 | 39 | for (int i = start; i < 4; i++) { 40 | arr[num] = text[i]; 41 | comb(num+1, i); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /BOJ/16922. 로마 숫자 만들기/oh_16922.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | /** 10 | * 16922.로마 숫자 만들기 11 | *

12 | * 중복조합 13 | */ 14 | public class oh_16922 { 15 | static int N, R, count; 16 | static boolean[] check; 17 | static int[] ch; 18 | static int[] input; 19 | static Set set; 20 | public static void main(String[] args) throws IOException { 21 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 22 | R = Integer.parseInt(br.readLine()); 23 | N = 4; 24 | count = 0; 25 | check = new boolean[N]; 26 | ch = new int[]{1,5,10,50}; 27 | input = new int[R]; 28 | set= new HashSet(); 29 | Dfs(0, 0); 30 | System.out.println(set.size()); 31 | } 32 | 33 | private static void Dfs(int cnt, int start) { 34 | if (cnt == R) { 35 | int sum=0; 36 | for (int c : input) { 37 | 38 | sum+=c; 39 | } 40 | set.add(sum); 41 | 42 | return; 43 | } 44 | for (int i = start; i < check.length; i++) { 45 | 46 | 47 | check[i] = true; 48 | input[cnt] = ch[i]; 49 | Dfs(cnt + 1, i); 50 | check[i] = false; 51 | 52 | 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BOJ/16922. 로마 숫자 만들기/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 16922.로마 숫자 만들기](https://boj.kr/16922) 2 | -------------------------------------------------------------------------------- /BOJ/17086.아기상어2/README.md: -------------------------------------------------------------------------------- 1 | [17086. 아기 상어 2](https://www.acmicpc.net/problem/17086) 2 | -------------------------------------------------------------------------------- /BOJ/17140.이차원배열과연산/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 17140. 이차원 배열과 연산](https://www.acmicpc.net/problem/17140) -------------------------------------------------------------------------------- /BOJ/17142. 연구소3/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 17142. 연구소3](https://www.acmicpc.net/problem/17142) 2 | -------------------------------------------------------------------------------- /BOJ/1719. 택배/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1719. 택배](https://www.acmicpc.net/problem/1719) 2 | -------------------------------------------------------------------------------- /BOJ/17208. 카우버거 알바생/README.md: -------------------------------------------------------------------------------- 1 | [17208. 카우버거 알바생](https://www.acmicpc.net/problem/17208) 2 | -------------------------------------------------------------------------------- /BOJ/1738. 골목길/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 1738. 골목길](https://www.acmicpc.net/problem/1738) 2 | -------------------------------------------------------------------------------- /BOJ/1774.우주신과의교감/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1774. 우주신과의 교감](https://www.acmicpc.net/problem/1774) -------------------------------------------------------------------------------- /BOJ/18405.경쟁적 전염/readme.md: -------------------------------------------------------------------------------- 1 | [BOJ18405.경쟁적 전염](https://www.acmicpc.net/problem/18405) 2 | -------------------------------------------------------------------------------- /BOJ/18428. 감시피하기/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 18428. 감시피하기](https://www.acmicpc.net/problem/18428) -------------------------------------------------------------------------------- /BOJ/1865. 웜홀/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 1865. 웜홀](https://www.acmicpc.net/problem/1865) 2 | 3 | 웜홀(wormhole)은 우주 공간에서 블랙홀(black hole)과 화이트홀(white hole)을 연결하는 통로를 의미하는 가상의 개념이다. 우주의 시간과 공간의 벽에 난 구멍에 비유할 수 있다. 웜홀에 관한 이론은 독일 태생 물리학자 아인슈타인의 상대성이론을 바탕으로 하고 있다. 4 | -------------------------------------------------------------------------------- /BOJ/1890. 점프/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 1890. 점프](https://www.acmicpc.net/problem/1890) 2 | -------------------------------------------------------------------------------- /BOJ/1941. 소문난 칠공주/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 1941. 소문난 칠공주 2 | ](https://www.acmicpc.net/problem/1941 3 | ) 4 | 5 | -------------------------------------------------------------------------------- /BOJ/1967. 트리의 지름/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 1967. 트리의 지름](https://www.acmicpc.net/problem/1967) 2 | -------------------------------------------------------------------------------- /BOJ/20437. 문자열 게임 2/README.md: -------------------------------------------------------------------------------- 1 | [20437. 문자열 게임 2](https://www.acmicpc.net/problem/20437) 2 | -------------------------------------------------------------------------------- /BOJ/20529. 가장 가까운 세사람의 심리적 거리/read.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /BOJ/2096. 내려가기/README.md: -------------------------------------------------------------------------------- 1 | [2096. 내려가기](https://www.acmicpc.net/problem/2096) 2 | -------------------------------------------------------------------------------- /BOJ/21608.상어초등학교/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 21608. 상어 초등학교](https://www.acmicpc.net/problem/21608) 2 | -------------------------------------------------------------------------------- /BOJ/21610. 마법사 상어와 비바라기/readme.md: -------------------------------------------------------------------------------- 1 | [21610.마법사 상어와 비바라기](https://www.acmicpc.net/problem/21610) 2 | -------------------------------------------------------------------------------- /BOJ/21921. 블로그/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 21921. 블로그](https://www.acmicpc.net/problem/21921) 2 | -------------------------------------------------------------------------------- /BOJ/21921. 블로그/haeun_21921.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_21921_블로그 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 11 | 12 | int N = Integer.parseInt(st.nextToken()); // 블로그 시작한지 N일 13 | int X = Integer.parseInt(st.nextToken()); // X일 탐색 14 | 15 | int[] people = new int[N]; // 방문자 수 16 | st = new StringTokenizer(br.readLine(), " "); 17 | for (int i = 0; i < N; i++) people[i] = Integer.parseInt(st.nextToken()); 18 | 19 | int max; // 최대 방문자 수 20 | int term = 1; // 기간 수(초기 1) 21 | int sum = 0; // 최댓값과 비교할 sum 변수 22 | 23 | // 방문자들의 합 계산 24 | for (int i = 0; i < X; i++) { 25 | sum += people[i]; 26 | } 27 | max = sum; 28 | 29 | // 슬라이딩 윈도우 30 | for (int i = X; i < N; i++) { 31 | sum += people[i] - people[i - X]; 32 | 33 | // 최댓값 갱신 34 | if (max < sum) { 35 | max = sum; 36 | // 기간 초기화 37 | term = 1; 38 | } 39 | // 기간 + 1 40 | else if (max == sum) term++; 41 | } 42 | 43 | // 출력 44 | if (max == 0) System.out.println("SAD"); 45 | else { 46 | System.out.println(max); // 최대 방문자 수 47 | System.out.println(term); // 기간 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /BOJ/2193. 이친수/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2193. 이친수](https://www.acmicpc.net/problem/2193) 2 | -------------------------------------------------------------------------------- /BOJ/2193. 이친수/ch.java: -------------------------------------------------------------------------------- 1 | package BOJ; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class BOJ_S3_2193_이친수 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | 11 | int N = Integer.parseInt(br.readLine()); 12 | long[] D = new long[N+1]; 13 | D[0] = 0; 14 | D[1] = 1; 15 | for (int i = 2; i <= N; ++i) { 16 | D[i] = D[i-1] + D[i-2]; 17 | } 18 | 19 | System.out.println(D[N]); 20 | 21 | br.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BOJ/2193. 이친수/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * 요구사항 : N이 주어지면, N자리의 이친수의 개수를 구해라 5 | * 이진수 : 0과 1로만 이루어진 수 6 | * 이친수 : 아래 조건을 만족하는 이진수 7 | * - 조건1. 0으로 시작하지 않는다. 8 | * - 조건2. 1이 두번 연속 나타나지 않는다. 9 | * 10 | * 점화식 : dp[i] = dp[i - 1] + dp[i - 2] 11 | * - dp[i-2]의 이친수들에서 i-1번째가 0이 오는 이친수들만 i번째에 1이 올 수 있고, 12 | * - dp[i-1]의 이친수들에서 0인지 1인지 상관없이 모두 i번째에 0이 올 수 있다고 봄 13 | * 14 | * 주의 : dp 결과값이 int 범위를 넘어서기 때문에 long으로 해줘야함 15 | */ 16 | public class chan { 17 | 18 | public static void main(String[] args) { 19 | Scanner sc = new Scanner(System.in); 20 | int N = sc.nextInt(); 21 | long[] dp = new long[N + 1]; 22 | dp[0] = 0; 23 | dp[1] = 1; 24 | for (int i = 2; i <= N; i++) { 25 | dp[i] = dp[i - 1] + dp[i - 2]; // 점화식 26 | } 27 | 28 | System.out.println(dp[N]); 29 | 30 | sc.close(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /BOJ/2193. 이친수/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class BOJ_2193_이친수 { 6 | 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int N = Integer.parseInt(br.readLine()); // N자리 10 | long[] memo = new long[N+1]; // 값 저장 11 | memo[0] = 0; 12 | memo[1] = 1; 13 | 14 | // DP 15 | for (int i = 2; i <= N; i++) { 16 | if (memo[i] == 0) memo[i] = memo[i-2] + memo[i-1]; 17 | } 18 | 19 | // 출력 20 | System.out.println(memo[N]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BOJ/2193. 이친수/oh.java: -------------------------------------------------------------------------------- 1 | package BOJ; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class BOJ2193 { 8 | static long[] memo; 9 | 10 | static long d(int n){ 11 | if(n>=2&&memo[n]==0){ 12 | memo[n]=d(n-1)+d(n-2); 13 | } 14 | return memo[n]; 15 | } 16 | public static void main(String[] args) throws IOException { 17 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 18 | int n = Integer.parseInt(br.readLine()); 19 | memo = new long[n+1]; 20 | memo[0]=0; 21 | memo[1]=1; 22 | System.out.println(d(n)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BOJ/2217.로프/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 2217. 로프](https://www.acmicpc.net/problem/2217) -------------------------------------------------------------------------------- /BOJ/22858.원상복구/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | public class chan { 5 | 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | String[] data = br.readLine().split(" "); 9 | int N = Integer.parseInt(data[0]); // 카드의 개수 10 | int K = Integer.parseInt(data[1]); // 카드를 섞은 횟수 11 | int[] S = new int[N + 1]; 12 | int[] D = new int[N + 1]; 13 | int[] P = new int[N + 1]; 14 | data = br.readLine().split(" "); 15 | for (int i = 1; i <= N; i++) { 16 | S[i] = Integer.parseInt(data[i - 1]); 17 | } 18 | data = br.readLine().split(" "); 19 | for (int i = 1; i <= N; i++) { 20 | D[i] = Integer.parseInt(data[i - 1]); 21 | } 22 | // 입력 받기 완료 23 | 24 | // K번 섞는다. 25 | for (int k = 0; k < K; k++) { 26 | // Di는 PDi 값을 i번째로 가져와서 Si에 저장했으므로 27 | // Si의 값을 P의 Di번째에 두는 것이 한 번 섞기 전의 카드 배치이다. 28 | for (int i = 1; i <= N; i++) { 29 | P[D[i]] = S[i]; 30 | } 31 | 32 | // Pi가 곧 이전에 카드 섞기의 결과이므로 Si가 Pi로 되어야한다. 33 | for (int i = 1; i <= N; i++) { 34 | S[i] = P[i]; 35 | } 36 | } 37 | 38 | // 결과 출력 39 | for (int i = 1; i <= N; i++) { 40 | System.out.print(P[i] + " "); 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /BOJ/2292.벌집/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2292. 벌집](https://www.acmicpc.net/problem/2292) 2 | -------------------------------------------------------------------------------- /BOJ/2292.벌집/ch.java: -------------------------------------------------------------------------------- 1 | package BOJ; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BOJ_B2_2292_벌집 { 6 | // N(1 ≤ N ≤ 1,000,000,000) 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int N = sc.nextInt(); 11 | 12 | int cnt = 1; 13 | int num = 2; 14 | 15 | if (N == 1) { 16 | System.out.print(1); 17 | } else { 18 | while (num <= N) { 19 | num = num + (6 * cnt); 20 | cnt++; 21 | } 22 | System.out.println(cnt); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BOJ/2292.벌집/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class chan { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int N = sc.nextInt(); 8 | 9 | int i = 0; 10 | int end = 1; 11 | while (true) { 12 | end = end + (6 * i); 13 | if (N <= end) break; 14 | i++; 15 | } 16 | System.out.println(i + 1); 17 | sc.close(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /BOJ/2292.벌집/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BOJ_2292_벌집 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int N = sc.nextInt(); // N번방 7 | int total = 0; // 지나는 방 8 | int num = 0; // 한 테두리 지나가기 9 | int next = 1; // 다음 테두리방에서 제일 큰 값 10 | 11 | while (true) { 12 | // N이 next보다 더 크다면 테두리를 하나 더 지나야하므로 total+1 13 | if (N > next) { 14 | total++; 15 | } 16 | // N이 next보다 작다면 이미 지나왔음, 반복문 탈출 17 | else break; 18 | // 다음 테두리에서 제일 큰 방 구하기 19 | next += 6*num; 20 | // 다음 테두리로 이동 21 | num++; 22 | } 23 | 24 | // N이 1번방일 때 25 | if (N == 1) total = 1; 26 | // 출력 27 | System.out.println(total); 28 | sc.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BOJ/2292.벌집/oh: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | /** 5 | * 1 7 19 37 61 6 | * 1 2 3 4 5 7 | * 8 | * 2-7=>2칸 9 | * 8-19=>3칸 10 | * 20-37=>4칸 11 | * 1 7 19 39 61 12 | * 계차수열을 이용하면 풀리는 문제 13 | */ 14 | public class BOJ2292 { 15 | public static void main(String[] args) throws IOException { 16 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 17 | int n = Integer.parseInt(br.readLine()); 18 | for (int i = 1; i < 100000; i++) { 19 | if(n<=1+3*(i*i)-3*i){ 20 | System.out.println(i); 21 | break; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BOJ/2343. 기타레슨/chan_2343.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | /** 6 | * 요구사항 : 총 N개의 강의를 같은 크기의 M개의 블루레이에 담으려고 할 때, 가능한 블루레이의 크기 중 최소를 구해라 7 | * 8 | * 이분탐색 : 블루레이의 크기를 이분탐색하며 찾아야한다. 9 | * @author chaeu 10 | * 11 | */ 12 | public class chan_2343 { 13 | public static void main(String[] args) throws Exception { 14 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 15 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 16 | int N = Integer.parseInt(st.nextToken()); 17 | int M = Integer.parseInt(st.nextToken()); 18 | int[] arr = new int[N]; 19 | st = new StringTokenizer(br.readLine(), " "); 20 | int start = 0, end = 0; // start는 최소 블루레이 크기, end는 최대 블루레이 크기 21 | for (int i = 0; i < N; i++) { 22 | arr[i] = Integer.parseInt(st.nextToken()); 23 | if (start < arr[i]) start = arr[i]; 24 | end += arr[i]; 25 | } 26 | 27 | while (start <= end) { 28 | int mid = (start + end) / 2; 29 | int sum = 0; // 한 그룹 내의 합을 구할 변수 30 | int count = 0; // 그룹 수 31 | // 앞에서부터 차례로 더하다가 mid보다 커지기 전까지의 수들을 한 그룹으로 묶기 32 | for (int i = 0; i < N; i++) { 33 | if (sum + arr[i] > mid) { 34 | sum = 0; 35 | count++; 36 | } 37 | sum += arr[i]; 38 | } 39 | if (sum > 0) count++; // 마지막 그룹 세기 40 | if (count <= M) end = mid - 1; 41 | else start = mid + 1; 42 | } 43 | System.out.println(start); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /BOJ/2343. 기타레슨/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 2343. 기타 레슨](https://www.acmicpc.net/problem/2343) 2 | -------------------------------------------------------------------------------- /BOJ/2460.지능형 기차2/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2455. 지능형 기차](https://www.acmicpc.net/problem/2455) 2 | -------------------------------------------------------------------------------- /BOJ/2460.지능형 기차2/ch.java: -------------------------------------------------------------------------------- 1 | package BOJ; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.StringTokenizer; 7 | 8 | public class BOJ_B3_2460_지능형기차2 { 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | StringTokenizer st = null; 12 | int sum = 0; 13 | int max = Integer.MIN_VALUE; 14 | for (int i = 0; i < 10; i++) { 15 | st = new StringTokenizer(br.readLine()); 16 | sum -= Integer.parseInt(st.nextToken()); // 내린 사람 17 | sum += Integer.parseInt(st.nextToken()); // 탄 사람 18 | max = Math.max(max, sum); 19 | } 20 | System.out.println(max); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BOJ/2460.지능형 기차2/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class chan { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int passengers = 0; // 현재 역에서의 사람 수 8 | int ans = 0; // 기차에 사람이 가장 많을 때의 사람 수 9 | for (int i = 0; i < 10; i++) { 10 | int getOff = sc.nextInt(); // 내린 사람 11 | int getOn = sc.nextInt(); // 탄 사람 12 | 13 | passengers += ( getOn - getOff); // 원래 타고있던 승객 수에서 내린 사람을 빼고, 탄 사람을 더하면 현재 역에서의 사람 수가 된다. 14 | 15 | ans = passengers > ans ? passengers : ans; // 기차에 사람이 가장 많은지 비교 16 | } 17 | System.out.println(ans); 18 | sc.close(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /BOJ/2460.지능형 기차2/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_2460_지능형기차2 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int max = Integer.MIN_VALUE; // 최대 인원 11 | int total = 0; // 기차에 사람 수 12 | for (int t = 0; t < 10; t++) { 13 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 14 | total -= Integer.parseInt(st.nextToken()); 15 | total += Integer.parseInt(st.nextToken()); 16 | // 최댓값 구하기 17 | if (total > max) max = total; 18 | } 19 | // 출력 20 | System.out.println(max); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BOJ/2460.지능형 기차2/oh_2460.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class oh_2460 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int T = 10; 10 | int sum = 0; 11 | int max = Integer.MIN_VALUE; 12 | for (int i = 0; i < T; i++) { 13 | StringTokenizer st = new StringTokenizer(br.readLine()); 14 | int min = Integer.parseInt(st.nextToken()); 15 | int plus = Integer.parseInt(st.nextToken()); 16 | sum += plus - min; 17 | max= Math.max(max,sum); 18 | } 19 | if(max>10000) max =10000; 20 | System.out.println(max); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BOJ/2467. 용액/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2467. 용액](https://www.acmicpc.net/problem/2467) 2 | -------------------------------------------------------------------------------- /BOJ/2467. 용액/ch_2467.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class ch_2467 { 8 | static int N, a = 0, b = 0, min = Integer.MAX_VALUE; 9 | static int[] arr; 10 | public static void main(String[] args) throws IOException { 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | N = Integer.parseInt(br.readLine()); 13 | arr = new int[N]; 14 | StringTokenizer st = new StringTokenizer(br.readLine()); 15 | for (int i = 0; i < N; i++) { 16 | arr[i] = Integer.parseInt(st.nextToken()); 17 | } 18 | Arrays.sort(arr); 19 | 20 | for (int i = 0; i < N; i++) { 21 | int left = i + 1; 22 | int right = N - 1; 23 | while (left <= right){ 24 | int mid = (left + right) / 2; 25 | int sum = Math.abs(arr[i] + arr[mid]); 26 | 27 | if (min > sum) { 28 | min = sum; 29 | a = arr[i]; 30 | b = arr[mid]; 31 | } 32 | if (arr[mid] == -arr[i]) break; 33 | else if (arr[mid] < -arr[i]) left = mid + 1; 34 | else right = mid - 1; 35 | } 36 | } 37 | System.out.println(a + " " + b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BOJ/2468. 안전영역/Readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 2468. 안전영역](https://www.acmicpc.net/problem/2468) 2 | -------------------------------------------------------------------------------- /BOJ/2529. 부등호/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2529. 부등호](https://www.acmicpc.net/problem/2529) 2 | -------------------------------------------------------------------------------- /BOJ/2564.경비원/readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /BOJ/2573. 빙산/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2573. 빙산](https://www.acmicpc.net/problem/2573) 2 | -------------------------------------------------------------------------------- /BOJ/2579.계단오르기/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2579. 계단 오르기](https://www.acmicpc.net/problem/2579) 2 | -------------------------------------------------------------------------------- /BOJ/2579.계단오르기/ch.java: -------------------------------------------------------------------------------- 1 | package BOJ; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | /** 8 | * 2579 9 | */ 10 | public class BOJ_2579 { 11 | public static void main(String[] args) throws IOException { 12 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | 14 | int N = Integer.parseInt(br.readLine()); 15 | int[] score = new int[300]; 16 | int[] max = new int[300]; 17 | 18 | for (int i = 0; i < N; i++) { 19 | score[i] = Integer.parseInt(br.readLine()); 20 | } 21 | 22 | max[0] = score[0]; 23 | max[1] = score[0] + score[1]; 24 | max[2] = Math.max(score[0], score[1]) + score[2]; 25 | 26 | for (int i = 3; i < N; i++) { 27 | max[i] = Math.max(max[i - 2], max[i - 3] + score[i - 1]) + score[i]; 28 | } 29 | 30 | System.out.println(max[N - 1]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /BOJ/2579.계단오르기/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | /** 5 | * 요구사항 : 계단에 쓰여있는 점수가 주어질 때, 조건에 맞게 얻을 수 있는 총 점수의 최댓값을 구해라 6 | * 조건 7 | * - 1. 연속된 세 개의 계단을 모두 밟으면 안 된다. 8 | * - 2. 마지막 도착 계단은 반드시 밟아야한다. 9 | * 10 | * 점화식 구하기 11 | * - 연속 세 개를 밟으면 안되니, 12 | * - 현재 계단에서의 dp[i]는 13 | * - 1) i-2번째 계단을 밟고, i번째를 밟을 때와, (dp[i - 2] + arr[i]) 14 | * - 2) i-2번째 계단을 밟지 않고 i-1번째 계단을 밟고 i번째 계단을 밟는 (dp[i - 3] + arr[i - 1] + arr[i]) 15 | * - 두 가지 방법 중 더 큰 값이 dp의 값이 된다. 16 | * 17 | * 주의사항 : N이 2일 때 조건을 잘 맞춰주어야함 18 | */ 19 | public class Main { 20 | 21 | public static void main(String[] args) throws Exception { 22 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 23 | int N = Integer.parseInt(br.readLine()); 24 | int[] arr = new int[N + 1]; 25 | int[] dp = new int[N + 1]; 26 | 27 | for (int i = 1; i <= N; i++) { 28 | arr[i] = Integer.parseInt(br.readLine()); 29 | } 30 | 31 | dp[0] = 0; 32 | dp[1] = arr[1]; 33 | 34 | if (N > 1) 35 | dp[2] = arr[1] + arr[2]; 36 | 37 | for (int i = 3; i <= N; i++) { 38 | dp[i] = Math.max(dp[i - 3] + arr[i - 1] + arr[i], dp[i - 2] + arr[i]); 39 | } 40 | System.out.println(dp[N]); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /BOJ/2579.계단오르기/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class BOJ_2579_계단오르기 { 6 | 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int N = Integer.parseInt(br.readLine()); // 계단의 개수 10 | int[] score = new int[N+1]; // 점수 11 | int[] dp = new int[N+1]; 12 | 13 | for (int i = 1; i <= N; i++) { 14 | score[i] = Integer.parseInt(br.readLine()); 15 | } 16 | 17 | // dp 18 | dp[0] = score[0]; 19 | dp[1] = dp[0] + score[1]; 20 | if (N >= 2) dp[2] = dp[1] + score[2]; 21 | for (int i = 3; i <= N; i++) { 22 | dp[i] = Math.max(dp[i-2], dp[i-3] + score[i-1]) + score[i]; 23 | } 24 | 25 | // 출력 26 | System.out.println(dp[N]); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BOJ/2589. 보물섬/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 2589. 보물섬](https://www.acmicpc.net/problem/2589) 2 | -------------------------------------------------------------------------------- /BOJ/2606.바이러스/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2606. 바이러스](https://www.acmicpc.net/problem/2606) 2 | -------------------------------------------------------------------------------- /BOJ/2631. 줄세우기/ch_2631.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class ch_2631 { 6 | public static void main(String[] args) throws IOException { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | int N = Integer.parseInt(br.readLine()); 9 | 10 | int ans = 0; 11 | int[] numbers = new int[N]; 12 | 13 | for (int i = 0; i < N; i++) { 14 | numbers[i] = Integer.parseInt(br.readLine()); 15 | } 16 | 17 | int[] DP = new int[N]; 18 | DP[0] = 1; 19 | 20 | for (int i = 1; i < N; i++) { 21 | DP[i] = 1; 22 | for (int j = 0; j < i; j++) { 23 | if (numbers[i] > numbers[j]) DP[i] = Math.max(DP[i], DP[j] + 1); 24 | } 25 | ans = Math.max(ans, DP[i]); 26 | } 27 | System.out.println(N - ans); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BOJ/2638. 치즈/Readme.md: -------------------------------------------------------------------------------- 1 | [백준- 2638. 치즈](https://www.acmicpc.net/problem/2638) 2 | -------------------------------------------------------------------------------- /BOJ/2644. 촌수계산/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2644. 촌수계산](https://www.acmicpc.net/problem/2644) 2 | -------------------------------------------------------------------------------- /BOJ/2665.미로만들기/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2665. 미로만들기](https://www.acmicpc.net/problem/2665) 2 | -------------------------------------------------------------------------------- /BOJ/2667. 단지번호붙이기/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 2667. 단지번호붙이기](https://www.acmicpc.net/problem/2667) 2 | -------------------------------------------------------------------------------- /BOJ/2671. 잠수함식별/README.md: -------------------------------------------------------------------------------- 1 | [2671. 잠수함식별](https://www.acmicpc.net/problem/2671) 2 | -------------------------------------------------------------------------------- /BOJ/2671. 잠수함식별/ch_2671.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.regex.Pattern; 5 | 6 | public class ch_2671 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | // 엔진소리 패턴 : (100~1~|01)~ 10 | String pattern = "(100+1+|01)+"; 11 | 12 | if (Pattern.matches(pattern, br.readLine())) System.out.println("SUBMARINE"); 13 | else System.out.println("NOISE"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BOJ/2671. 잠수함식별/chan_2671.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | /** 5 | * 6 | * 특정 잠수함에서 나오는 소리인지 아닌지를 알아내라. 7 | * - 잠수함의 엔진소리 패턴 : (100~1~|01)~ 8 | * 잠수함의 소리 : 0과 1 두 종류의 연속으로 이루어짐 9 | * ~ : 한 특정한 소리의 반복 10 | * (x|y) : x나 y 중 하나만을 선택해서 만들 수 있는 소리의 집합 11 | * @author chaeu 12 | * 13 | */ 14 | public class chan_2671 { 15 | 16 | public static void main(String[] args) throws Exception { 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | String regex = "(100+1+|01)+"; 19 | if (br.readLine().matches(regex)) { 20 | System.out.println("SUBMARINE"); 21 | } else { 22 | System.out.println("NOISE"); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /BOJ/2671. 잠수함식별/haeun_2671.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BOJ_2671_잠수함식별 { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | String sound = sc.next(); // 잠수함의 소리 9 | String pattern = "(100+1+|01)+"; // 패턴 10 | 11 | // 출력 12 | if (sound.matches(pattern)) System.out.println("SUBMARINE"); 13 | else System.out.println("NOISE"); 14 | 15 | sc.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BOJ/2671. 잠수함식별/oh_2671.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * @packageName : BOJ.Gold 11 | * @fileName : BOJ2671 12 | * @date : 2022-01-05 13 | * @language : JAVA 14 | * @classification : regex 15 | * @time_limit : 2sec 16 | * @required_time : 00:40 ~ 01:22 17 | * @submissions : 1 18 | * @description : 19 | **/ 20 | public class oh_2671 { 21 | public static void main(String[] args) throws IOException { 22 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 23 | String str = br.readLine(); 24 | Pattern pattern = Pattern.compile("^(100+1+|01)+$"); 25 | Matcher matcher = pattern.matcher(str); 26 | if(matcher.matches()){ 27 | System.out.println("SUBMARINE"); 28 | }else{ 29 | System.out.println("NOISE"); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /BOJ/2887.행성터널/README.md: -------------------------------------------------------------------------------- 1 | [BOJ 2887. 행성 터널](https://www.acmicpc.net/problem/2887) -------------------------------------------------------------------------------- /BOJ/4781. 사탕가게/readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 4781. 사탕가게](https://www.acmicpc.net/problem/4781) 2 | -------------------------------------------------------------------------------- /BOJ/47821. 사탕가게/ch_4781.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class ch_4781 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = null; 10 | 11 | while (true) { 12 | st = new StringTokenizer(br.readLine()); 13 | int n = Integer.parseInt(st.nextToken()); 14 | int m = (int) Math.round(Double.parseDouble(st.nextToken()) * 100); 15 | 16 | if (n == 0 && m == 0) break; 17 | 18 | int[] c = new int[n + 1]; 19 | int[] p = new int[n + 1]; 20 | int[] DP = new int[10001]; 21 | 22 | for (int i = 1; i <= n; i++) { 23 | st = new StringTokenizer(br.readLine()); 24 | c[i] = Integer.parseInt(st.nextToken()); 25 | p[i] = (int) Math.round(Double.parseDouble(st.nextToken()) * 100); 26 | } 27 | 28 | for (int i = 1; i <= n; i++) { 29 | for (int j = p[i]; j <= m; j++) { 30 | DP[j] = Math.max(DP[j], DP[j - p[i]] + c[i]); 31 | } 32 | } 33 | 34 | System.out.println(DP[m]); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /BOJ/47821. 사탕가게/chan_4781.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | public class chan_4781 { 6 | 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | 10 | while (true) { 11 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 12 | 13 | int n = Integer.parseInt(st.nextToken()); // 사탕 종류의 수 14 | int m = (int) Math.round(Float.parseFloat(st.nextToken()) * 100); // 가진 돈의 양 (소수점 없애주기 위해 100 곱하기) 15 | 16 | if (n == 0 && m == 0) break; 17 | 18 | int[] c = new int[n + 1]; // 사탕의 칼로리 19 | int[] p = new int[n + 1]; // 사탕의 가격 (소수점 없애주기 위해 100 곱하기) 20 | 21 | for (int i = 1; i <= n; i++) { 22 | st = new StringTokenizer(br.readLine(), " "); 23 | c[i] = Integer.parseInt(st.nextToken()); 24 | p[i] = (int) Math.round(Float.parseFloat(st.nextToken()) * 100); 25 | } 26 | 27 | int[] D = new int[10001]; 28 | 29 | for (int i = 1; i <= n; i++) { 30 | for (int j = p[i]; j <= m; j++) { 31 | D[j] = Math.max(D[j], c[i] + D[j - p[i]]); 32 | } 33 | } 34 | System.out.println(D[m]); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /BOJ/47821. 사탕가게/haeun_4781.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class BOJ_4781_사탕가게 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 11 | 12 | while (st.hasMoreTokens()) { 13 | int n = Integer.parseInt(st.nextToken()); // 사탕 종류의 수 14 | int m = (int) Math.round(Double.parseDouble(st.nextToken()) * 100); // 가지고 있는 돈의 양 15 | 16 | // 종료조건 17 | if (n == 0 && m == 0) break; 18 | 19 | int[] c = new int[n]; // 칼로리 20 | int[] p = new int[n]; // 가격 21 | int[] dp = new int[m+1]; 22 | 23 | for (int i = 0; i < n; i++) { 24 | st = new StringTokenizer(br.readLine(), " "); 25 | c[i] = Integer.parseInt(st.nextToken()); 26 | p[i] = (int) Math.round(Double.parseDouble(st.nextToken()) * 100); 27 | } 28 | 29 | // dp 30 | for (int i = 0; i < n; i++) { 31 | for (int j = 0; j <= m; j++) { 32 | // 구매 가능 33 | if (j - p[i] >= 0) dp[j] = Math.max(dp[j], dp[j-p[i]] + c[i]); 34 | } 35 | } 36 | 37 | // 출력 38 | System.out.println(dp[m]); 39 | st = new StringTokenizer(br.readLine(), " "); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /BOJ/4963. 섬의 개수/Readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 4963. 섬의 개수](https://www.acmicpc.net/problem/4963) 2 | -------------------------------------------------------------------------------- /BOJ/5972. 택배배송/Readme.md: -------------------------------------------------------------------------------- 1 | [백준. 5972 - 택배배송](https://www.acmicpc.net/problem/5972) 2 | -------------------------------------------------------------------------------- /BOJ/6603.로또/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 6603. 로또](https://www.acmicpc.net/problem/6603) 2 | -------------------------------------------------------------------------------- /BOJ/6603.로또/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.io.StringReader; 4 | 5 | public class chan { 6 | 7 | static int[] input, numbers; 8 | static int k; 9 | public static void main(String[] args) throws Exception { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | br = new BufferedReader(new StringReader("7 1 2 3 4 5 6 7\r\n" + 12 | "8 1 2 3 5 8 13 21 34\r\n" + 13 | "0")); 14 | 15 | while(true) { 16 | String[] data = br.readLine().split(" "); 17 | // 0이 입력되면 프로그램 종료 18 | if (data[0].equals("0")) break; 19 | k = Integer.parseInt(data[0]); 20 | input = new int[k]; 21 | numbers = new int[6]; 22 | for (int i = 0; i < k; i++) { 23 | input[i] = Integer.parseInt(data[i + 1]); 24 | } 25 | selectNumbers(0, 0); 26 | System.out.println(); 27 | } 28 | } 29 | // k개의 숫자에서 6개의 수를 뽑는 모든 경우의 수 출력하기 30 | static void selectNumbers(int cnt, int start) { 31 | if (cnt == 6) { 32 | for (int i = 0; i < 6; i++) { 33 | System.out.print(numbers[i] + " "); 34 | } 35 | System.out.println(); 36 | return; 37 | } 38 | 39 | for (int i = start; i < k; i++) { 40 | numbers[cnt] = input[i]; 41 | selectNumbers(cnt + 1, i + 1); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /BOJ/6603.로또/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class BOJ_6603_로또 { 6 | private static int[] arr, result; 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | while (true) { 11 | String str = br.readLine(); 12 | // 0이면 반복문 탈출 13 | if (str.equals("0")) break; 14 | String[] temp = str.split(" "); 15 | 16 | arr = new int[temp.length]; // K개 뽑기 17 | result = new int[6]; // 6개를 고르는 경우의 수 18 | 19 | for (int i = 1; i < temp.length; i++) { 20 | arr[i] = Integer.parseInt(temp[i]); 21 | } 22 | // 조합 23 | comb(0, 1); 24 | // 빈 줄 출력 25 | System.out.println(); 26 | } 27 | } 28 | 29 | // 조합 30 | private static void comb(int cnt, int start) { 31 | // 기저조건 32 | if (cnt == result.length) { 33 | // 출력 34 | for (int i = 0; i < result.length; i++) { 35 | System.out.print(result[i] + " "); 36 | } 37 | System.out.println(); 38 | return; 39 | } 40 | 41 | for (int i = start; i < arr.length; i++) { 42 | result[cnt] = arr[i]; 43 | comb(cnt+1, i+1); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /BOJ/6603.로또/oh: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | // 백준 N과 M을 풀었다면 쉽게 풀수 있을 지도 3 | public class Main { 4 | static int r,n; 5 | static boolean isSelect[]; 6 | static int input[]; 7 | static int arr[]; 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | while (true){ 12 | n=sc.nextInt(); 13 | if(n==0){break;} 14 | r=6; 15 | arr =new int[r]; 16 | input= new int[n]; 17 | isSelect=new boolean[n]; 18 | for (int i = 0; i < input.length; i++) { 19 | input[i]=sc.nextInt(); 20 | } 21 | dfs(0,0); 22 | System.out.println(); 23 | 24 | } 25 | } 26 | static void dfs(int cnt,int start){ 27 | if(cnt==r){ 28 | for (int z : arr) { 29 | System.out.print(z+" "); 30 | } 31 | System.out.println(); 32 | return; 33 | } 34 | for (int i=start; i < input.length; i++) { 35 | if(isSelect[i]) continue; 36 | arr[cnt]=input[i]; 37 | isSelect[i]=true; 38 | dfs(cnt+1,i+1); 39 | isSelect[i]=false; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /BOJ/7562. 나이트의 이동/Readme.md: -------------------------------------------------------------------------------- 1 | [백준 - 7562. 나이트의 이동](https://www.acmicpc.net/problem/7562) 2 | -------------------------------------------------------------------------------- /BOJ/7795. 먹을 것인가 먹힐 것인가/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 7795. 먹을 것인가 먹힐 것인가](https://www.acmicpc.net/problem/7795) 2 | -------------------------------------------------------------------------------- /BOJ/7795. 먹을 것인가 먹힐 것인가/haeun_7795.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class BOJ_7795_먹을것인가먹힐것인가 { 8 | 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | int T = Integer.parseInt(br.readLine()); // 테스트케이스의 개수 12 | 13 | for (int tc = 1; tc <= T; tc++) { 14 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 15 | int N = Integer.parseInt(st.nextToken()); // A의 수 16 | int M = Integer.parseInt(st.nextToken()); // B의 수 17 | int[] A = new int[N]; 18 | int[] B = new int[M]; 19 | int cnt = 0; 20 | 21 | // A 22 | st = new StringTokenizer(br.readLine(), " "); 23 | for (int i = 0; i < N; i++) A[i] = Integer.parseInt(st.nextToken()); 24 | 25 | // B 26 | st = new StringTokenizer(br.readLine(), " "); 27 | for (int i = 0; i < M; i++) B[i] = Integer.parseInt(st.nextToken()); 28 | 29 | // 정렬 30 | Arrays.sort(A); 31 | Arrays.sort(B); 32 | 33 | // A가 B보다 큰 쌍의 개수 구하기 34 | for (int i : A) { 35 | for (int j : B) { 36 | if (i > j) cnt++; 37 | else break; 38 | } 39 | } 40 | 41 | // 출력 42 | System.out.println(cnt); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /BOJ/9342. 염색체/README.md: -------------------------------------------------------------------------------- 1 | [백준 - 9342. 염색체](https://www.acmicpc.net/problem/9342) 2 | -------------------------------------------------------------------------------- /BOJ/9342. 염색체/ch_9342.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.regex.Pattern; 5 | 6 | public class ch_9342 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int T = Integer.parseInt(br.readLine()); 10 | 11 | // () : 한 문자로 인식 12 | // ? : 앞 문자가 없거나 하나 13 | // + : 앞 문자가 하나 이상 14 | // $ : 문자열 종료 15 | String pattern = "(A|B|C|D|E|F)?A+F+C+(A|B|C|D|E|F)?$"; 16 | 17 | for (int t = 0; t < T; t++) { 18 | if (Pattern.matches(pattern, br.readLine())) System.out.println("Infected!"); 19 | else System.out.println("Good"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BOJ/9342. 염색체/chan_9342.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | public class chan_9342 { 5 | 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | int T = Integer.parseInt(br.readLine()); 9 | for (int t = 0; t < T; t++) { 10 | String regex = "[A-F]?A+F+C+[A-F]?$"; 11 | String dna = br.readLine(); 12 | boolean result = dna.matches(regex); 13 | if (result) { 14 | System.out.println("Infected!"); 15 | } else { 16 | System.out.println("Good"); 17 | } 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /BOJ/9342. 염색체/haeun_9342.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BOJ_9342_염색체 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int T = sc.nextInt(); // 테스트 케이스의 수 7 | String rule = "^[A-F]?A+F+C+[A-F]?$"; // 규칙 8 | 9 | for (int tc = 1; tc <= T; tc++) { 10 | String str = sc.next(); // 염색체 문자열 11 | 12 | // 출력 13 | if (str.matches(rule)) System.out.println("Infected!"); 14 | else System.out.println("Good"); 15 | } 16 | sc.close(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BOJ/9342. 염색체/oh_9342.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * @packageName : BOJ.Silver 11 | * @fileName : BOJ9342 12 | * @date : 2021-12-31 13 | * @language : JAVA 14 | * @classification : regex 15 | * @time_limit : 2sec 16 | * @required_time : 00:40 ~ 01:22 17 | * @submissions : 1 18 | * @description : 19 | **/ 20 | public class oh_9342 { 21 | public static void main(String[] args) throws IOException { 22 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 23 | int T = Integer.parseInt(br.readLine()); 24 | for (int i = 0; i < T ; i++) { 25 | String str = br.readLine(); 26 | Pattern pattern = Pattern.compile("(A|B|C|D|E|F)?A{1,}F{1,}C{1,}(A|B|C|D|E|F)?"); 27 | Matcher matcher = pattern.matcher(str); 28 | if(matcher.matches()){ 29 | System.out.println("Infected!"); 30 | }else{ 31 | System.out.println("Good"); 32 | } 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BOJ/9465. 스티커: -------------------------------------------------------------------------------- 1 | [백준- 9465. 스티커](https://www.acmicpc.net/problem/9465) 2 | -------------------------------------------------------------------------------- /BOJ/9996. 한국이 그리울 땐 서버에 접속하지/ch_9996.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | import java.util.regex.Pattern; 6 | 7 | public class ch_9996 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | StringTokenizer st = null; 11 | 12 | int T = Integer.parseInt(br.readLine()); 13 | String pattern = br.readLine().replace("*", "[a-z]*"); 14 | // * : 앞 문자가 없을 수도 무한정 많을 수도 있음 15 | // [a - z] : 문자의 집합이나 범위를 나타내며 두 문자 사이는 - 기호로 범위를 나타낸다. 16 | // [] 내에서 ^ 가 선행하여 존재하면 not을 나타낸다. 17 | for (int i = 0; i < T; i++) { 18 | if (Pattern.matches(pattern, br.readLine())) System.out.println("DA"); 19 | else System.out.println("NE"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BOJ/9996. 한국이 그리울 땐 서버에 접속하지/chan_9996.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | public class chan_9996 { 5 | 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | int T = Integer.parseInt(br.readLine()); 9 | String pattern = br.readLine(); 10 | pattern = pattern.replace("*", "[a-z]*"); 11 | for (int t = 0; t < T; t++) { 12 | String fileName = br.readLine().trim(); 13 | boolean result = fileName.matches(pattern); // 비교할 문자열.matches(regex) 순서 지키기 14 | if (result) { 15 | System.out.println("DA"); 16 | } else { 17 | System.out.println("NE"); 18 | } 19 | 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /BOJ/9996. 한국이 그리울 땐 서버에 접속하지/haeun_9996.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BOJ_9996_한국이그리울땐서버에접속하지 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int N = sc.nextInt(); // 파일의 개수 7 | String pattern = sc.next(); // 패턴 8 | // 패턴의 시작과 끝 추출 9 | int idx = pattern.indexOf("*"); 10 | String start = pattern.substring(0, idx); 11 | String end = pattern.substring(idx+1, pattern.length()); 12 | 13 | for (int i = 1; i <= N; i++) { 14 | String file = sc.next(); 15 | 16 | // 만일 file 문자열의 길이가 패턴의 길이보다 작다면 "NE" 출력 17 | if (file.length() < pattern.length()-1) { 18 | System.out.println("NE"); 19 | continue; 20 | } 21 | 22 | // 패턴 일치 23 | if (file.substring(0, start.length()).equals(start) 24 | && file.substring(file.length()-end.length(), file.length()).equals(end)) { 25 | System.out.println("DA"); 26 | continue; 27 | } 28 | 29 | // 패턴 불일치 30 | System.out.println("NE"); 31 | } 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BOJ/9996. 한국이 그리울 땐 서버에 접속하지/oh_9996.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.StringTokenizer; 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | /** 11 | * @packageName : BOJ.Silver 12 | * @fileName : BOJ9996 13 | * @date : 2021-12-31 14 | * @language : JAVA 15 | * @classification : regex 16 | * @time_limit : 2sec 17 | * @required_time : 00:40 ~ 01:22 18 | * @submissions : 1 19 | * @description : 20 | **/ 21 | public class oh_9996 { 22 | public static void main(String[] args) throws IOException { 23 | StringBuilder sb = new StringBuilder(); 24 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 25 | int T = Integer.parseInt(br.readLine()); // testcase 26 | String str = br.readLine(); // pattern 27 | str = str.replace("*", "\\w*"); 28 | Pattern pattern = Pattern.compile("^"+str+"$"); 29 | for (int i = 0; i < T; i++) { 30 | String file = br.readLine(); 31 | Matcher matcher = pattern.matcher(file); 32 | if (matcher.matches()) { 33 | sb.append("DA" + "\n"); 34 | } else { 35 | sb.append("NE" + "\n"); 36 | } 37 | } 38 | System.out.println(sb); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /BOJ/9996. 한국이 그리울 땐 서버에 접속하지/readme.md: -------------------------------------------------------------------------------- 1 | [백준. 9996 - 한국이 그리울 땐 서버에 접속하지](https://www.acmicpc.net/problem/9996) 2 | -------------------------------------------------------------------------------- /SWEA/10505.소득 불균형/Expert10505.java: -------------------------------------------------------------------------------- 1 | package exD3; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | import java.util.Scanner; 7 | 8 | 9 | public class Expert10505 { 10 | public static void main(String[] args) throws IOException { 11 | String data ="3\n" + 12 | "7\n" + 13 | "15 15 15 15 15 15 15\n" + 14 | "10\n" + 15 | "1 1 1 1 1 1 1 1 1 100\n" + 16 | "7\n" + 17 | "2 7 1 8 2 8 4"; 18 | 19 | Scanner sc = new Scanner(System.in); 20 | sc= new Scanner(data); 21 | 22 | 23 | int T= sc.nextInt(); 24 | for(int test_case=1;test_case<=T;test_case++){ 25 | int N = sc.nextInt(); 26 | int sum=0; 27 | int[] arr = new int[N]; 28 | for(int i=0;i al = new ArrayList<>(); 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int T = Integer.parseInt(sc.nextLine()); 10 | for (int t = 1; t <= T; t++) { 11 | String ans = ""; 12 | String str = sc.nextLine(); 13 | int[] arr = new int[26]; // 소문자 개수 26개 14 | for (int i = 0; i < str.length(); i++) { 15 | arr[str.charAt(i) - 'a']++; 16 | } 17 | 18 | for (int i = 0; i < arr.length; i++) { 19 | if (arr[i] % 2 != 0) { 20 | char ch = (char)(i + 'a'); 21 | ans += ch; 22 | } 23 | } 24 | 25 | if (ans == "") { 26 | System.out.println("#" + t + " " + "Good"); 27 | } 28 | else { 29 | System.out.println("#" + t + " " + ans); 30 | } 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /SWEA/10912. 외로운 문자/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.Arrays; 4 | 5 | // 1. 입력받은 알파벳 수 세서 홀짝인지 비교하는 방법 6 | // 2. 입력받은 알파벳들 정렬해서 옆에랑 짝이 맞는지 확인하는 방법 7 | public class chan { 8 | 9 | public static void main(String[] args) throws Exception { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | int T = Integer.parseInt(br.readLine()); 12 | for (int t = 1; t <= T; t++) { 13 | StringBuffer sb = new StringBuffer(); 14 | char[] input = br.readLine().toCharArray(); 15 | Arrays.sort(input); // 입력 문자들 사전순 정렬 16 | 17 | // 정렬했을 때 다음 원소랑 같으면 짝이 있는 것 18 | for (int i = 0; i < input.length; i++) { 19 | // 지금 원소가 다음 원소랑 같으면 다다음 원소로 이동 20 | if (i < input.length - 1 && input[i] == input[i + 1]) { 21 | i++; 22 | } 23 | // 지금 원소가 다음 원소랑 다르면 지금 원소를 sb에 추가 24 | else { 25 | sb.append(input[i]); 26 | } 27 | } 28 | 29 | System.out.print("#" + t + " " ); 30 | if (sb.length() == 0) { 31 | System.out.println("Good"); 32 | } else System.out.println(sb.toString()); 33 | 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /SWEA/10912. 외로운 문자/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | 6 | public class SW_D3_10912_외로운문자 { 7 | 8 | public static void main(String[] args) throws NumberFormatException, IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int T = Integer.parseInt(br.readLine()); // 테스트케이스 개수 11 | 12 | for (int tc = 1; tc <= T; tc++) { 13 | String result = ""; 14 | String str = br.readLine(); // 문자열 15 | char[] arr = new char[str.length()]; 16 | for (int i = 0; i < arr.length; i++) { 17 | arr[i] = str.charAt(i); 18 | } 19 | // 오름차순으로 정렬 20 | Arrays.sort(arr); 21 | for (int i = 0; i < arr.length; i++) { 22 | // 같은 문자열 짝짓기 23 | if (i < arr.length-1 && arr[i] == arr[i+1]) { 24 | i++; 25 | continue; 26 | } 27 | // 남은 문자열 28 | else { 29 | result += arr[i]; 30 | } 31 | } 32 | // 어떤 문자도 남지 않았을 때 33 | if (result == "") result = "Good"; 34 | // 출력 35 | System.out.printf("#%d %s\n", tc, result); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SWEA/10912. 외로운 문자/oh.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.io.StringReader; 5 | import java.util.ArrayList; 6 | 7 | public class Expert10912 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 10 | 11 | int T = Integer.parseInt(br.readLine()); 12 | for (int test_case = 1; test_case <= T; test_case++) { 13 | //알파벳을 인덱스 값으로 쓴다 14 | int[] alpha = new int[26]; 15 | String str = br.readLine(); 16 | for (int i = 0; i < str.length(); i++) { 17 | alpha[str.charAt(i)-'a']++; 18 | 19 | } 20 | // 홀수만 따로 배열에 담는다 21 | ArrayList ch = new ArrayList<>(); 22 | for (int i = 0; i < alpha.length; i++) { 23 | if(alpha[i]%2==1){ 24 | ch.add((char)(i+97)); 25 | } 26 | 27 | } 28 | //배열이 비었다면 good 29 | System.out.print("#"+test_case+" "); 30 | if(ch.isEmpty()){ 31 | System.out.print("Good"); 32 | }else{ 33 | for (Character c : ch) { 34 | System.out.print(c); 35 | } 36 | } 37 | System.out.println(); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SWEA/1206.View/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | public class chan { 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | StringTokenizer st = null; 9 | for (int t = 1; t <= 10; t++) { 10 | int ans = 0; // 조망권 확보 세대 수 11 | int N = Integer.parseInt(br.readLine()); 12 | int[] building = new int[N]; // 지역 빌딩들의 높이 13 | st = new StringTokenizer(br.readLine(), " "); 14 | // 빌딩 높이 입력받기 15 | for (int i = 0; i < N; i++) { 16 | building[i] = Integer.parseInt(st.nextToken()); 17 | } 18 | // 맨 앞에서 두번째까지와 맨 뒤에서 두번째까지는 건물이 없는 걸 고려하여 범위 지정 19 | for (int i = 2; i < N - 2; i++) { 20 | int h = building[i]; // 현재 탐색중인 빌딩의 높이 21 | // 가까운 왼쪽 빌딩 두개와 오른쪽 빌딩 두개의 높이가 현재 빌딩보다 높으면 조망권이 없으므로 다음 빌딩 탐색 22 | if (building[i - 2] > h || building[i - 1] > h || building[i + 1] > h || building[i+2] > h) continue; 23 | // 현재 빌딩에서 좌우 두칸 빌딩중 가장 높은 빌딩을 빼준 것이 조망권이 확보된 세대이다. 24 | ans += (h - highest(building[i - 2], building[i - 1], building[i + 1], building[i + 2])); 25 | } 26 | 27 | System.out.printf("#%d %d%n", t, ans); 28 | } 29 | } 30 | 31 | // 4개의 빌딩 중 가장 높은 빌딩의 층 수 반환 32 | private static int highest(int i, int j, int k, int l) { 33 | return Math.max(Math.max(i, j), Math.max(k, l)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SWEA/1206.View/changhyun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SWEA_D3_1206_View { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | for (int t = 1; t <= 10; t++) { 8 | int W = sc.nextInt(); 9 | int[] build = new int[W]; 10 | int ans = 0; 11 | int interrupt = 0; 12 | 13 | for(int i = 0; i < W; i++) { 14 | build[i] = sc.nextInt(); 15 | } 16 | 17 | for(int i = 2; i < W - 2; i++) { 18 | 19 | interrupt = Math.max(build[i-2], Math.max(build[i-1], Math.max(build[i+1], build[i+2]))); 20 | if(build[i] - interrupt > 0) { 21 | ans += build[i] - interrupt; 22 | } 23 | 24 | 25 | } 26 | System.out.println("#" + t + " " + ans); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /SWEA/1206.View/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // 알고리즘스터디 4 | public class SW_D3_1206_View { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | for (int tc = 1; tc <= 10; tc++) { 9 | int len = sc.nextInt(); // 지역의 길이 10 | int[] arr = new int[len]; 11 | 12 | // 빌딩 채우기 13 | for (int i = 0; i < len; i++) { 14 | arr[i] = sc.nextInt(); 15 | // 예외처리 16 | if (arr[i] > 255) return; 17 | } 18 | 19 | int total = 0; 20 | 21 | // 빌딩들을 순회하면서 좌우 2칸 공백 측정 22 | for (int i = 2; i < len - 2; i++) { 23 | // 조망권 확보를 위한 공백 측정 24 | int cnt = 0; 25 | int max = -1; 26 | for (int j = -2; j <= 2; j++) { 27 | // 자신 제외 28 | if (j == 0) continue; 29 | // 자신을 제외한 빌딩중 가장 높은 빌딩을 max에 저장 30 | if (max < arr[i+j]) max = arr[i+j]; 31 | // 조망권이 확보될 때 32 | if (arr[i] - arr[i+j] >= 1) { 33 | cnt++; 34 | } 35 | } 36 | // 좌우 2칸 공백을 만족할 때, 조망권을 확보한 세대를 total에 합산 37 | if (cnt == 4) { 38 | total += arr[i] - max; 39 | } 40 | } 41 | System.out.printf("#%d %d\n", tc, total); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SWEA/1206.View/jamoon.java: -------------------------------------------------------------------------------- 1 | package exD3; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.util.Scanner; 6 | 7 | public class jamoon { 8 | public static void main(String[] args) throws FileNotFoundException { 9 | //System.setIn(new FileInputStream("C:\\ALGO\\algo\\src\\input1206.txt")); 10 | Scanner sc = new Scanner(System.in); 11 | int T=10; 12 | for(int test_case=1;test_case<=T;test_case++){ 13 | int size=sc.nextInt(); 14 | int[] arr = new int[size]; 15 | //배열담기 16 | for(int i =0;i= 0; i--, j--) { 20 | if (str.charAt(i) == match.charAt(j)) cnt--; 21 | } 22 | if (cnt == 0) total++; 23 | 24 | // 출력 25 | System.out.printf("#%d %d\n", T, total); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SWEA/1215.회문1/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.FileInputStream; 3 | import java.io.InputStreamReader; 4 | 5 | public class chan { 6 | 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | 10 | for (int t = 1; t <= 10; t++) { 11 | int ans = 0; 12 | int findLen = Integer.parseInt(br.readLine()); 13 | char[][] board = new char[8][8]; 14 | for (int i = 0; i < 8; i++) { 15 | char[] line = br.readLine().toCharArray(); 16 | for (int j = 0; j < 8; j++) { 17 | board[i][j] = line[j]; 18 | } 19 | } 20 | 21 | for (int i = 0; i < 8; i++) { 22 | for (int j = 0; j < 8 - findLen + 1; j++) { 23 | int cnt = 1; 24 | while(cnt <= findLen / 2) { 25 | if (board[i][j + cnt - 1] != board[i][j + findLen - cnt]) break; 26 | if (cnt == findLen/2) ans++; 27 | cnt++; 28 | } 29 | } 30 | } 31 | for (int j = 0; j < 8; j++) { 32 | for (int i = 0; i < 8 - findLen + 1; i++) { 33 | int cnt = 1; 34 | while(cnt <= findLen / 2) { 35 | if (board[i + cnt - 1][j] != board[i + findLen - cnt][j]) break; 36 | if (cnt == findLen/2) ans++; 37 | cnt++; 38 | } 39 | } 40 | } 41 | 42 | System.out.println("#" + t + " " + ans); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /SWEA/1217.거듭제곱/ch.java: -------------------------------------------------------------------------------- 1 | package SWEA; 2 | 3 | import java.io.IOException; 4 | import java.util.Scanner; 5 | 6 | public class SWEA_4일차_거듭제곱 { 7 | public static void main(String[] args) throws IOException { 8 | Scanner sc = new Scanner(System.in); 9 | for (int t = 1; t <= 10 ; t++) { 10 | sc.nextInt(); // 테스트케이스 번호 11 | System.out.println("#" + t + " " + calc(sc.nextInt(), sc.nextInt())); 12 | } 13 | } 14 | 15 | private static int calc(int num, int cnt) { 16 | if (cnt == 0) return 1; 17 | return num * calc(num, cnt - 1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SWEA/1217.거듭제곱/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class chan { 4 | 5 | static int ans; 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | for (int t = 0; t < 10; t++) { 9 | int tc = sc.nextInt(); 10 | int N = sc.nextInt(); 11 | int M = sc.nextInt(); 12 | 13 | System.out.println("#" + tc + " " + pow(N, M)); 14 | } 15 | } 16 | 17 | private static int pow(int n, int m) { 18 | if (m == 0) return 1; 19 | return n * pow(n, m - 1); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /SWEA/1217.거듭제곱/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SW_D3_1217_거듭제곱 { 4 | private static int N, M, result; 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | for (int tc = 1; tc <= 10; tc++) { 9 | int T = sc.nextInt(); // 테스트케이스 번호 10 | 11 | N = sc.nextInt(); // N의 12 | M = sc.nextInt(); // M 거듭제곱 13 | result = 1; 14 | 15 | solve(0); 16 | // 출력 17 | System.out.printf("#%d %d\n", T, result); 18 | } 19 | sc.close(); 20 | } 21 | 22 | // 거듭제곱 23 | private static void solve(int cnt) { 24 | if (cnt == M) return; 25 | result *= N; 26 | solve(cnt+1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SWEA/1217.거듭제곱/oh.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class Expert1217 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); 9 | for (int i = 0; i < 10; i++) { 10 | int P=Integer.parseInt(br.readLine()); 11 | StringTokenizer st = new StringTokenizer(br.readLine()); 12 | int N=Integer.parseInt(st.nextToken()); 13 | int M=Integer.parseInt(st.nextToken()); 14 | 15 | System.out.println("#"+P+" "+power(N,M)); 16 | } 17 | } 18 | static int power(int n,int m){ 19 | if(m==1) return n; 20 | return n*power(n,m-1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SWEA/1219.길찾기/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class SW_D4_1219_길찾기 { 7 | public static int result; 8 | public static int[] arr1, arr2; 9 | 10 | public static void main(String[] args) throws IOException { 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | for (int tc = 1; tc <= 10; tc++) { 13 | StringTokenizer st = new StringTokenizer(br.readLine()); 14 | int T = Integer.parseInt(st.nextToken()); // 테스트케이스 번호 15 | int N = Integer.parseInt(st.nextToken()); // 순서쌍의 개수 16 | arr1 = new int[100]; 17 | arr2 = new int[100]; 18 | result = 0; // 유효한 길인지 검사 19 | st = new StringTokenizer(br.readLine()); 20 | // 데이터 저장 21 | for (int i = 0; i < N; i++) { 22 | int current = Integer.parseInt(st.nextToken()); 23 | int next = Integer.parseInt(st.nextToken()); 24 | if (arr1[current] == 0) arr1[current] = next; 25 | else arr2[current] = next; 26 | } 27 | solve(arr1[0]); 28 | solve(arr2[0]); 29 | // 출력 30 | System.out.printf("#%d %d\n", T, result); 31 | } 32 | } 33 | public static void solve(int index) { 34 | if (index == 0) return; 35 | // 도착지점까지 갔다면 유효함 36 | if (index == 99){ 37 | result = 1; 38 | return; 39 | } 40 | solve(arr1[index]); 41 | solve(arr2[index]); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SWEA/1221.GNS/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class chan { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 | int T = Integer.parseInt(br.readLine()); 8 | 9 | for (int t = 1; t <= T; t++) { 10 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 11 | System.out.println(st.nextToken()); 12 | int len = Integer.parseInt(st.nextToken()); 13 | st = new StringTokenizer(br.readLine(), " "); 14 | String[] input = {"ZRO", "ONE", "TWO", "THR", "FOR", "FIV", "SIX", "SVN", "EGT", "NIN"}; 15 | int[] cnt = new int[10]; 16 | for (int i = 0; i < len; i++) { 17 | String index = st.nextToken(); 18 | for (int j = 0; j < input.length; j++) { 19 | if (index.equals(input[j])) { 20 | cnt[j]++; 21 | break; 22 | } 23 | } 24 | } 25 | for (int i = 0; i < cnt.length; i++) { 26 | for (int j = 0; j < cnt[i]; j++) { 27 | System.out.print(input[i] + " "); 28 | } 29 | } 30 | System.out.println(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /SWEA/1221.GNS/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class SW_D3_1221_GNS { 8 | 9 | public static void main(String[] args) throws IOException { 10 | String[] num = {"ZRO", "ONE", "TWO", "THR", "FOR", "FIV", "SIX", "SVN", "EGT", "NIN"}; 11 | 12 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | int T = Integer.parseInt(br.readLine()); // 테스트케이스 개수 14 | 15 | for (int tc = 1; tc <= T; tc++) { 16 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 17 | int trash = st.nextToken().charAt(1)-'0'; // 테스트케이스 번호 18 | int N = Integer.parseInt(st.nextToken()); // 테스트케이스 길이 19 | StringBuilder sb = new StringBuilder(); // 결과값 20 | int[] count = new int[10]; 21 | 22 | st = new StringTokenizer(br.readLine(), " "); 23 | for (int i = 0; i < N; i++) { 24 | String str = st.nextToken(); 25 | // 숫자에 해당하는 인덱스값에 +1 26 | count[Arrays.asList(num).indexOf(str)]++; 27 | } 28 | 29 | // 문자열 정렬 30 | for (int i = 0; i < count.length; i++) { 31 | while (count[i]-- != 0) { 32 | sb.append(num[i]).append(" "); 33 | } 34 | } 35 | 36 | // 출력 37 | System.out.printf("#%d\n", tc); 38 | System.out.println(sb); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SWEA/1222.계산기1/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.LinkedList; 5 | import java.util.Queue; 6 | 7 | public class SW_D4_1222_계산기1 { 8 | 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | for (int tc = 1; tc <= 10; tc++) { 12 | Queue queue = new LinkedList(); 13 | int len = Integer.parseInt(br.readLine()); // 문자열의 길이 14 | String cal = br.readLine(); // 계산식 15 | int result = 0; 16 | 17 | // 후위 표기식으로 계산 18 | for (int i = 0; i < len; i++) { 19 | if (cal.charAt(i) == '+' || i == len-1) { 20 | // 마지막 값 저장 21 | if (i == len-1) queue.offer(cal.charAt(i)-'0'); 22 | // 계산할 값이 하나라면 생략 23 | if (queue.size() == 1) continue; 24 | // 계산 25 | int num1 = queue.poll(); 26 | int num2 = queue.poll(); 27 | result = num1 + num2; 28 | queue.offer(result); 29 | } 30 | // 숫자라면 queue에 저장 31 | else queue.offer(cal.charAt(i)-'0'); 32 | } 33 | 34 | // 출력 35 | System.out.printf("#%d %d\n", tc, result); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SWEA/1226.미로1/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.FileInputStream; 3 | import java.io.InputStreamReader; 4 | 5 | public class Solution { 6 | 7 | static int[][] maze; 8 | static boolean[][] visited; 9 | static int ans; 10 | public static void main(String[] args) throws Exception { 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | 13 | for (int t = 1; t <= 10; t++) { 14 | int tc = Integer.parseInt(br.readLine()); 15 | ans = 0; // 판단. 0 또는 1 16 | maze = new int[16][16]; 17 | visited = new boolean[16][16]; 18 | 19 | // 미로 입력받기 20 | for (int i = 0; i < 16; i++) { 21 | char[] data = br.readLine().toCharArray(); 22 | for (int j = 0; j < 16; j++) { 23 | maze[i][j] = data[j] - '0'; 24 | } 25 | } 26 | 27 | dfs(1, 1); 28 | 29 | System.out.println("#" + tc + " " + ans); 30 | } 31 | } 32 | 33 | static int[] dx = {-1, 1, 0, 0}; 34 | static int[] dy = {0, 0, -1, 1}; 35 | private static boolean dfs(int x, int y) { 36 | if (maze[x][y] == 3) { 37 | ans = 1; 38 | return true; 39 | } 40 | for (int i = 0; i < 4; i++) { 41 | int nx = dx[i] + x; 42 | int ny = dy[i] + y; 43 | 44 | if (nx < 1 || ny < 1 || nx > 16 || ny > 16 || visited[nx][ny] || maze[nx][ny] == 1) continue; 45 | 46 | visited[nx][ny] = true; 47 | if (dfs(nx, ny)) return true; 48 | } 49 | return false; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /SWEA/1226.미로1/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class SW_D4_1226_미로1 { 6 | // 4방탐색 7 | public static int dx[] = {-1, 1, 0, 0}; 8 | public static int dy[] = {0, 0, -1, 1}; 9 | public static char map[][]; 10 | public static int result; 11 | 12 | public static void main(String[] args) throws IOException { 13 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 14 | for (int tc = 1; tc <= 10; tc++) { 15 | int T = Integer.parseInt(br.readLine()); // 테스트케이스 번호 16 | map = new char[16][16]; // 미로 17 | result = 0; // 유효성 판단 18 | // 미로 19 | for (int i = 0; i < 16; i++) { 20 | String str = br.readLine(); 21 | map[i] = str.toCharArray(); 22 | } 23 | // 출발지점 24 | dfs(1, 1); 25 | // 출력 26 | System.out.printf("#%d %d\n", tc, result); 27 | } 28 | } 29 | 30 | public static void dfs(int x, int y) { 31 | // 4방탐색 32 | for (int d = 0; d < 4; d++) { 33 | int nx = x + dx[d]; 34 | int ny = y + dy[d]; 35 | // 길이 막혀있거나 범위를 벗어난다면 다음 값 탐색 36 | if (nx < 0 || ny < 0 || nx >= 16 || ny >= 16 || map[nx][ny] == '1') continue; 37 | // 도착지점에 도착했다면, 유효한 미로 38 | if (map[nx][ny] == '3') { 39 | result = 1; 40 | return; 41 | } 42 | // 방문완료 43 | map[nx][ny] = '1'; 44 | dfs(nx, ny); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /SWEA/1231.중위순회/ch.java: -------------------------------------------------------------------------------- 1 | package SWEA; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class SWEA_D4_1231_중위순회 { 8 | static int N; 9 | static char[] alpabet; 10 | public static void main(String[] args) throws IOException { 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | 13 | for (int t = 1; t <= 10; t++) { 14 | N = Integer.parseInt(br.readLine()); 15 | alpabet = new char[N + 1]; 16 | for (int i = 1; i <= N; i++) { 17 | String[] str = br.readLine().split(" "); 18 | alpabet[i] = str[1].charAt(0); 19 | } 20 | System.out.print("#" + t + " "); 21 | inorder(1); 22 | System.out.println(); 23 | } 24 | } 25 | 26 | private static void inorder(int cnt) { 27 | if (cnt > N) { 28 | return; 29 | } 30 | 31 | inorder(cnt * 2); 32 | System.out.print(alpabet[cnt]); 33 | inorder(cnt * 2 + 1); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SWEA/1231.중위순회/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.FileInputStream; 3 | import java.io.InputStreamReader; 4 | 5 | public class chan { 6 | static int N; 7 | static char[] input; 8 | public static void main(String[] args) throws Exception { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | for (int t = 1; t <= 10; t++) { 11 | // 입력받기 12 | N = Integer.parseInt(br.readLine()); 13 | input = new char[N + 1]; 14 | for (int i = 1; i <= N; i++) { 15 | String[] data = br.readLine().split(" "); 16 | input[i] = data[1].charAt(0); 17 | } 18 | // 입력받기 완료 19 | 20 | System.out.print("#" + t + " " ); 21 | recur(1); // 루트노드부터 재귀 22 | System.out.println(); 23 | } 24 | } 25 | 26 | private static void recur(int i) { 27 | if (i > N) { 28 | return; 29 | } 30 | recur(i * 2); // 왼쪽 자식 먼저 재귀 31 | System.out.print(input[i]); // 자신 출력하기 32 | recur(i * 2 + 1); // 오른쪽 자식 재귀 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /SWEA/1234. 비밀번호/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class SW_D3_1234_비밀번호 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | for (int tc = 1; tc <= 10; tc++) { 11 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 12 | int N = Integer.parseInt(st.nextToken()); // 문자열의 길이 13 | String num = st.nextToken(); // 문자열 14 | 15 | // 문자열 탐색 16 | for (int i = 0; i < num.length(); i++) { 17 | // 같은 번호로 붙어있는 쌍 발견 18 | if (i+1 < num.length() && num.charAt(i) == num.charAt(i+1)) { 19 | // 왼쪽 오른쪽 쌍 탐색 20 | int left = -1; 21 | int right = 1; 22 | while (i+left >= 0 && i+right+1 < num.length() && num.charAt(i+left) == num.charAt(i+1+right)) { 23 | left--; 24 | right++; 25 | } 26 | // 소거하는 쌍을 제외한 왼쪽 문자열 잘라내기 27 | String strLeft = num.substring(0, i+left+1); 28 | // 소거하는 쌍을 제외한 오른쪽 문자열 잘라내기 29 | String strRight = num.substring(i+right+1, num.length()); 30 | // 문자열 합쳐서 다시 처음부터 소거 31 | num = strLeft.concat(strRight); 32 | i = -1; 33 | } 34 | } 35 | // 출력 36 | System.out.printf("#%d %s\n", tc, num); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /SWEA/1234. 비밀번호/oh.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Stack; 5 | import java.util.StringTokenizer; 6 | 7 | public class Expert1234 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int T = 10; 11 | for (int test_case = 1; test_case <= T; test_case++) { 12 | StringTokenizer st = new StringTokenizer(br.readLine()); 13 | int N = Integer.parseInt(st.nextToken()); 14 | Stack stack = new Stack<>(); 15 | String str = st.nextToken(); 16 | for (int j = 0; j < N; j++) { 17 | if (!stack.isEmpty()&&stack.peek() == Character.getNumericValue(str.charAt(j))) { 18 | stack.pop(); 19 | } else { 20 | stack.push(Character.getNumericValue(str.charAt(j))); 21 | } 22 | 23 | } 24 | System.out.print("#" + test_case+" "); 25 | for (Integer n : stack) { 26 | System.out.printf("%d",n); 27 | } 28 | System.out.println(); 29 | 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /SWEA/1860. 진기의 최고급 붕어빵/ch.java: -------------------------------------------------------------------------------- 1 | package SWEA; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.Scanner; 7 | 8 | 9 | public class SWEA_D3_1860_진기의최고급붕어빵 { 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int tc = sc.nextInt(); 13 | 14 | for(int t = 1; t <= tc; t++) { 15 | int N = sc.nextInt(); 16 | int M = sc.nextInt(); 17 | int K = sc.nextInt(); 18 | ArrayList a = new ArrayList<>(); 19 | boolean flag = false; 20 | 21 | for(int i = 0; i < N; i++) { 22 | int tmp = sc.nextInt(); 23 | a.add(tmp); 24 | } 25 | 26 | Collections.sort(a); 27 | for(int i = 0; i < N; i++) { 28 | int tmp = a.get(i); 29 | int sum = K * (tmp / M); 30 | if(sum < (i + 1)) 31 | flag = true; 32 | } 33 | if(!flag) 34 | System.out.println("#" + t + " " + "Possible"); 35 | else 36 | System.out.println("#" + t + " " + "Impossible"); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /SWEA/2817.부분 수열의 합/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SW_D3_2817_부분수열의합 { 4 | 5 | private static int N, K, total; 6 | private static int[] arr; 7 | private static boolean[] checked; 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int T = sc.nextInt(); // 테스트 케이스의 수 12 | 13 | for (int tc = 1; tc <= T; tc++) { 14 | N = sc.nextInt(); // N개의 정수 15 | K = sc.nextInt(); // 목표 합 16 | arr = new int[N]; // 수열 17 | checked = new boolean[N]; 18 | for (int i = 0; i < N; i++) { 19 | arr[i] = sc.nextInt(); 20 | } 21 | total = 0; 22 | solve(0); 23 | // 출력 24 | System.out.printf("#%d %d\n", tc, total); 25 | } 26 | sc.close(); 27 | } 28 | 29 | // 부분 수열의 합 구하기 30 | private static void solve(int cnt) { 31 | if (cnt == N) { 32 | int sum = 0; 33 | for (int i = 0; i < N; i++) { 34 | if (checked[i]) sum += arr[i]; 35 | } 36 | if (sum == K) total++; 37 | return; 38 | } 39 | checked[cnt] = true; 40 | solve(cnt+1); 41 | checked[cnt] = false; 42 | solve(cnt+1); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SWEA/4192. 수영대회(완전탐색)/README.md: -------------------------------------------------------------------------------- 1 | [SWEA - 4192. 수영대회(완전탐색)](https://swexpertacademy.com/main/code/userProblem/userProblemDetail.do?contestProbId=AWKaCc-KABgDFAT2) 2 | -------------------------------------------------------------------------------- /SWEA/6719. 성수의 프로그래밍 강좌 시청/ch.java: -------------------------------------------------------------------------------- 1 | package SWEA; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Scanner; 6 | 7 | public class SWEA_D4_성수의프로그래밍 { 8 | public static void main(String[] args) throws Exception{ 9 | Scanner sc = new Scanner(System.in); 10 | int tc = sc.nextInt(); 11 | 12 | for(int t = 1; t <= tc; t++) { 13 | int n = sc.nextInt(); 14 | int k = sc.nextInt(); 15 | double r = 0; 16 | ArrayList al = new ArrayList<>(); 17 | for(int i = 0; i < n; i++) { 18 | int tmp = sc.nextInt(); 19 | al.add(tmp); 20 | } 21 | 22 | Collections.sort(al); 23 | 24 | for(int i = al.size() - k; i < al.size(); i++) { 25 | r = (r + al.get(i)) / 2; 26 | } 27 | System.out.printf("#%d %.6f\n", t, r); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /SWEA/6719. 성수의 프로그래밍 강좌 시청/haeun.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.StringTokenizer; 6 | 7 | public class SW_D4_6719_성수의프로그래밍강좌시청 { 8 | 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | int T = Integer.parseInt(br.readLine()); // 테스트케이스 개수 12 | 13 | for (int tc = 1; tc <= T; tc++) { 14 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 15 | int N = Integer.parseInt(st.nextToken()); // 강좌 개수 16 | int K = Integer.parseInt(st.nextToken()); // K개 시청 17 | int[] video = new int[N]; 18 | double grade = 0; 19 | 20 | // 강좌 수준 21 | st = new StringTokenizer(br.readLine(), " "); 22 | for (int i = 0; i < N; i++) { 23 | video[i] = Integer.parseInt(st.nextToken()); 24 | } 25 | // 오름차순으로 정렬 26 | Arrays.sort(video); 27 | for (int i = N-K; i < N; i++) { 28 | grade = (grade+video[i])/2; 29 | } 30 | // 출력 31 | System.out.printf("#%d %.6f\n", tc, grade); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /SWEA/7102.준홍이의 카드놀이/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class chan { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int T = sc.nextInt(); 7 | 8 | for (int t = 1; t <= T; t++) { 9 | StringBuffer sb = new StringBuffer("#" + t + " "); 10 | // 테케 별 N, M 입력받기 11 | int N = sc.nextInt(); 12 | int M = sc.nextInt(); 13 | 14 | /* 15 | N = 6, M = 3이라면 카드를 한장씩 골라 숫자를 합하는 경우의 수는 16 | N\M 1 2 3 17 | 1 2 3 4 18 | 2 3 4 5 19 | 3 4 5 6 20 | 4 5 6 7 21 | 5 6 7 8 22 | 6 7 8 9 23 | 가장 많이 등장하는 값은 위의 표에서 가장 긴 대각선에 해당하는 값이다. 24 | N 인덱스를 기준으로, [M][1]부터 [N][1]까지의 수가 가장 많이 등장하는 값이다. 25 | */ 26 | // N이 더 길다면 N 인덱스 기준 27 | if (N >= M) { 28 | for (int i = M; i <= N; i++) { 29 | sb.append(1 + i).append(" "); 30 | } 31 | } else { // M이 더 길다면 M 인덱스 기준 32 | for (int i = N; i <= M; i++) { 33 | sb.append(1 + i).append(" "); 34 | } 35 | } 36 | 37 | System.out.println(sb.toString()); 38 | } 39 | sc.close(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SWEA/7102.준홍이의 카드놀이/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int T = sc.nextInt(); // 테스트케이스 개수 8 | 9 | for (int tc = 1; tc <= T; tc++) { 10 | int N = sc.nextInt(); // 1~N번 카드 11 | int M = sc.nextInt(); // 1~M번 카드 12 | int[] numCount = new int[N + M + 1]; // 등장하는 숫자의 개수를 담을 배열 13 | 14 | // 합계의 빈도수 구하기 15 | for (int i = 1; i <= N; i++) { 16 | for (int j = 1; j <= M; j++) { 17 | numCount[i + j]++; 18 | } 19 | } 20 | 21 | // 최댓값 구하기 22 | int max = -1; 23 | for (int num : numCount) if (max < num) max = num; 24 | 25 | // 출력 26 | System.out.print("#" + tc + " "); 27 | for (int num = 1; num < numCount.length; num++) { 28 | if (numCount[num] == max) System.out.printf("%d ", num); 29 | } 30 | System.out.println(); 31 | } 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /SWEA/7102.준홍이의 카드놀이/oh.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Expert7102 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | String data = 7 | "2\n" + 8 | "6 6\n" + 9 | "6 4"; 10 | sc=new Scanner(data); 11 | int T =sc.nextInt(); 12 | for (int test_case = 1; test_case <= T; test_case++) { 13 | int N=sc.nextInt(); 14 | int M=sc.nextInt(); 15 | int sum[]= new int[N+M+1]; 16 | for (int i = 1; i <= N; i++) { 17 | for (int j = 1; j <= M; j++) { 18 | sum[i+j]++; 19 | } 20 | } 21 | int max = Integer.MIN_VALUE; 22 | for (int i : sum) { 23 | max=Math.max(max,i); 24 | } 25 | System.out.print("#"+test_case+" "); 26 | for (int i = 0; i < sum.length; i++) { 27 | if (sum[i]==max){ 28 | System.out.printf("%d ",i); 29 | } 30 | } 31 | System.out.println(); 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SWEA/8016.홀수 피라미드/chan.java: -------------------------------------------------------------------------------- 1 | public class chan { 2 | public static void main(String[] args) { 3 | Scanner sc = new Scanner(System.in); 4 | int T = sc.nextInt(); 5 | for (int t = 1; t <= T; t++) { 6 | long N = sc.nextInt(); // 층의 번호 7 | 8 | long right = N * N * 2 - 1; // 홀수 피라미드 각 층의 제일 오른쪽 숫자 구하는 규칙 9 | long left = right - 2 * (N * 2 - 2); // 층을 이루는 숫자의 개수에 곱하기 2를 구해서 right에서 뺀 것이 맨 왼쪽 숫자임 10 | // N이 1일 때만 규칙이 적용되지 않는다. 11 | if (N == 1) { 12 | left = right = 1; 13 | } 14 | System.out.printf("#%d %d %d%n", t, left, right); 15 | } 16 | sc.close(); 17 | } 18 | } 19 | // 계차수열 규칙 찾아서 반복문 돌렸으나 제약조건(1<=N<=10^9)때문에 안됨.(테케 4개만 정답) 20 | // 반복문 안쓰는 규칙 찾아서 left, right 찾았지만 int 타입으로 생성했어서 안됨(테케 6개 정답) 21 | // int 형은 대략 +-21억 정도인데 층만 최댓값이 10억이니 표현 범위가 부족! 22 | // ==> long(8바이트) 타입을 써야함 -------------------------------------------------------------------------------- /SWEA/8016.홀수 피라미드/changHyun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SWEA_D3_8016_홀수피라미드 { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int T = sc.nextInt(); 8 | long floor = 0; 9 | 10 | for (int t = 1; t <= T; t++) { 11 | floor = sc.nextInt(); 12 | if( floor == 1) { 13 | System.out.println("#" + t + " " + floor + " " + floor); 14 | continue; 15 | } 16 | long R = floor * floor * 2 -1; 17 | long L = R - (floor * 2 - 2) * 2; 18 | 19 | System.out.println("#" + t + " " + L + " " + R); 20 | } 21 | } 22 | } 23 | 24 | //재귀함수 사용시 런타임 에러 25 | /*long N = 3, K = 7; 26 | long L = 1; 27 | long R = 1; 28 | if(floor == 1) { 29 | System.out.println("#" + t + " " + floor + " " + floor); 30 | continue; 31 | }else if(floor == 2) { 32 | System.out.println("#" + t + " " + N + " " + K); 33 | continue; 34 | }else { 35 | L += permutation(2, floor); 36 | R += permutation(6, floor); 37 | System.out.println("#" + t + " " + L + " " + R); 38 | } 39 | } 40 | } 41 | 42 | 43 | private static long permutation(long sum, long cnt) { 44 | if(cnt < 2) { 45 | return 0; 46 | } 47 | return sum + permutation(sum + 4, cnt - 1); 48 | }*/ 49 | -------------------------------------------------------------------------------- /SWEA/8016.홀수 피라미드/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SW_D3_8016_홀수피라미드 { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int T = sc.nextInt(); // 테스트 케이스의 수 7 | 8 | for (int tc = 1; tc <= T; tc++) { 9 | long N = sc.nextInt(); // N층 10 | 11 | long left = 2*(N-1)*(N-1) + 1; 12 | long right = 2*N*N - 1; 13 | 14 | // 출력 15 | System.out.printf("#%d %d %d\n", tc, left, right); 16 | } 17 | sc.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SWEA/8016.홀수 피라미드/oh.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | 3 | import java.util.Scanner; 4 | 5 | 6 | public class Expert8016 { 7 | public static void main(String[] args) throws IOException { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int T = sc.nextInt(); 11 | 12 | 13 | int L = 1; 14 | int R = 1; 15 | for (int test_case = 1; test_case <= T; test_case++) { 16 | long amount = 0; 17 | long amount2 = 0; 18 | int layer = sc.nextInt(); 19 | for (int i = 1; i < layer; i++) { 20 | amount += 4 * i - 2; 21 | amount2 += 4 * i + 2; 22 | } 23 | System.out.print("#" + test_case + " "); 24 | System.out.print(L + amount + " "); 25 | System.out.print(R + amount2 + "\n"); 26 | 27 | } 28 | 29 | 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /SWEA/8382. 방향 전환/README.md: -------------------------------------------------------------------------------- 1 | [SWEA - 8382. 방향 전환](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWyNQrCahHcDFAVP#none) 2 | -------------------------------------------------------------------------------- /SWEA/8382. 방향 전환/ch_방향전환.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class ch_방향전환 { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | StringTokenizer st = null; 10 | int T = Integer.parseInt(br.readLine()); 11 | 12 | for (int t = 1; t <= T; t++) { 13 | int ans = 0; 14 | st = new StringTokenizer(br.readLine()); 15 | int x1 = Integer.parseInt(st.nextToken()); 16 | int y1 = Integer.parseInt(st.nextToken()); 17 | int x2 = Integer.parseInt(st.nextToken()); 18 | int y2 = Integer.parseInt(st.nextToken()); 19 | 20 | int x = Math.abs(x1 - x2); 21 | int y = Math.abs(y1 - y2); 22 | if ((x + y) % 2 == 0){ 23 | ans = Math.max(x, y) * 2; 24 | }else { 25 | ans = Math.max(x, y) * 2 - 1; 26 | } 27 | System.out.println("#" + t + " " + ans); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SWEA/8382. 방향 전환/chan_8382.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.StringTokenizer; 4 | 5 | public class chan_8382 { 6 | 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int T = Integer.parseInt(br.readLine()); 10 | for (int t = 1; t <= T; t++) { 11 | int ans = 0; 12 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 13 | int x1 = Integer.parseInt(st.nextToken()); 14 | int y1 = Integer.parseInt(st.nextToken()); 15 | int x2 = Integer.parseInt(st.nextToken()); 16 | int y2 = Integer.parseInt(st.nextToken()); 17 | // (x1, y1), (x2, y2) 입력받기 완료 18 | 19 | int a = Math.abs(x1 - x2); 20 | int b = Math.abs(y1 - y2); 21 | // 규칙 - 짝수일 때는 둘 중 큰 값 * 2, 홀수일 때는 둘 중 큰 값 * 2 - 1 22 | if ((a + b) % 2 == 0) ans = Math.max(a, b) * 2; 23 | else ans = Math.max(a, b) * 2 - 1; 24 | System.out.println("#" + t + " " + ans); 25 | } 26 | } 27 | } 28 | /* 29 | 3 30 | 0 0 1 0 31 | -1 -1 0 0 32 | 0 0 0 2 33 | */ -------------------------------------------------------------------------------- /SWEA/8382. 방향 전환/haeun_8382.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | public class SW_D4_8382_방향전환 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int T = Integer.parseInt(br.readLine()); // 테스트케이스의 수 11 | 12 | for (int tc = 1; tc <= T; tc++) { 13 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 14 | // 출발 15 | int x1 = Integer.parseInt(st.nextToken()); 16 | int y1 = Integer.parseInt(st.nextToken()); 17 | // 도착 18 | int x2 = Integer.parseInt(st.nextToken()); 19 | int y2 = Integer.parseInt(st.nextToken()); 20 | 21 | // 거리 구하기 22 | int x = Math.abs(x2 - x1); 23 | int y = Math.abs(y2 - y1); 24 | 25 | // 이동 횟수 26 | int answer = 0; 27 | 28 | // 짝수일 때 29 | if ((x + y) % 2 == 0) answer = Math.max(x, y) * 2; 30 | // 홀수일 때 31 | else answer = Math.max(x, y) * 2 - 1; 32 | 33 | // 출력 34 | System.out.printf("#%d %d\n", tc, answer); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /SWEA/8931.제로/ch.java: -------------------------------------------------------------------------------- 1 | package SWEA; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.Stack; 7 | 8 | public class SWEA_D3_8931 { 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | Stack s = new Stack<>(); 12 | int T = Integer.parseInt(br.readLine()); 13 | for (int t = 1; t <= T; t++) { 14 | int K = Integer.parseInt(br.readLine()); 15 | for (int k = 0; k < K; k++) { 16 | int num = Integer.parseInt(br.readLine()); 17 | if(num != 0) { 18 | s.push(num); 19 | }else { 20 | s.pop(); 21 | } 22 | } 23 | int sum = 0; 24 | int size = s.size(); 25 | for (int i = 0; i < size; i++) { 26 | sum += s.pop(); 27 | } 28 | System.out.println("#" + t + " " + sum); 29 | } 30 | } 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /SWEA/8931.제로/chan.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.FileInputStream; 3 | import java.io.InputStreamReader; 4 | import java.util.ArrayList; 5 | 6 | public class chan { 7 | public static void main(String[] args) throws Exception { 8 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9 | int T = Integer.parseInt(br.readLine()); 10 | 11 | for (int t = 1; t <= T; t++) { 12 | int ans = 0; 13 | int K = Integer.parseInt(br.readLine()); // 재현이가 수를 얼만큼 부를지 14 | ArrayList ledger = new ArrayList<>(K); 15 | int value; 16 | for (int k = 0; k < K; k++) { 17 | value = Integer.parseInt(br.readLine()); // 재현이가 부른 수 18 | if (value == 0) ledger.remove(ledger.size() - 1); // 제로를 외쳤으면 마지막에 쓰고 안 지운 수 지우기 19 | else ledger.add(value); // 제로가 아니면 재현이가 부른 수를 장부에 적기 20 | } 21 | 22 | // 지운 수를 빼고 적힌 수들을 모두 더한다. 23 | for (int i = 0; i < ledger.size(); i++) { 24 | ans += ledger.get(i); 25 | } 26 | 27 | System.out.println("#" + t + " " + ans); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SWEA/8931.제로/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Stack; 3 | 4 | public class SW_D3_8931_제로 { 5 | public static void main(String[] args) { 6 | Stack stack = new Stack<>(); 7 | Scanner sc = new Scanner(System.in); 8 | int T = sc.nextInt(); // 테스트 케이스의 수 9 | 10 | for (int tc = 1; tc <= T; tc++) { 11 | int K = sc.nextInt(); // 정수의 수 12 | int total = 0; 13 | for (int i = 0; i < K; i++) { 14 | int num = sc.nextInt(); 15 | if (num == 0) stack.pop(); // 정수가 0일 경우 최근 정수 제거 16 | else stack.push(num); // 가격을 stack에 담기 17 | } 18 | 19 | // 합계 구하기 20 | while (!stack.isEmpty()) total += stack.pop(); 21 | // 출력 22 | System.out.printf("#%d %d\n", tc, total); 23 | } 24 | sc.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /programmers/2019 카카오 개발자 겨울 인턴십/크레인 인형뽑기 게임/ch_64061.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | public class ch_64061 { 4 | public int solution(int[][] board, int[] moves) { 5 | int answer = 0; 6 | Stack st = new Stack<>(); 7 | 8 | // 크레인 이동 9 | outer: for(int i = 0; i < moves.length; i++){ 10 | // 높이만큼 반복하여 인형 찾기 11 | for(int j = 0; j < board[0].length; j++){ 12 | int pick = board[j][moves[i] - 1]; 13 | 14 | // 인형이 있으면 15 | if(pick != 0){ 16 | // 해당 칸 비우기 17 | board[j][moves[i] - 1] = 0; 18 | 19 | // 아무것도 없거나 가장 위의 인형과 넣을 인형이 같지 않으면 20 | if(st.isEmpty() || st.peek() != pick){ 21 | st.push(pick); 22 | }else { 23 | st.pop(); 24 | // 같은 두개 터트리기 25 | answer += 2; 26 | } 27 | continue outer; 28 | } 29 | } 30 | } 31 | return answer; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /programmers/2019 카카오 개발자 겨울 인턴십/크레인 인형뽑기 게임/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class chan { 5 | public int solution(int[][] board, int[] moves) { 6 | int answer = 0; 7 | int N = board.length; 8 | Stack stack = new Stack<>(); 9 | 10 | for (int m = 0; m < moves.length; m++) { 11 | for (int i = 0; i < N; i++) { 12 | int pickedDoll = board[i][moves[m] - 1]; 13 | 14 | if (pickedDoll != 0) { 15 | board[i][moves[m] - 1] = 0; // 뽑은 인형 자리는 빈 칸으로 변경 16 | 17 | // 바구니에 같은 모양의 인형이 제일 위에 없다면 지금 집은 인형 바구니에 넣기 18 | if (stack.size() == 0 || stack.peek() != pickedDoll) { 19 | stack.push(pickedDoll); 20 | } else { // 바구니 제일 위에 같은 모양의 인형 있으면 터뜨리기 21 | stack.pop(); 22 | answer += 2; 23 | } 24 | break; 25 | } 26 | } 27 | } 28 | 29 | return answer; 30 | } 31 | } -------------------------------------------------------------------------------- /programmers/2020 KAKAO BLIND RECRUITMENT/괄호 변환/README.md: -------------------------------------------------------------------------------- 1 | [level2 괄호 변환](https://programmers.co.kr/learn/courses/30/lessons/60058) 2 | -------------------------------------------------------------------------------- /programmers/2020 KAKAO BLIND RECRUITMENT/문자열 압축/README.md: -------------------------------------------------------------------------------- 1 | [문자열 압축](https://programmers.co.kr/learn/courses/30/lessons/60057) 2 | -------------------------------------------------------------------------------- /programmers/2020 KAKAO BLIND RECRUITMENT/실패율/ch_실패율.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ch_실패율 { 7 | class Solution { 8 | public int[] solution(int N, int[] stages) { 9 | int[] answer = new int[N]; 10 | double users = stages.length; 11 | List fail_rate = new ArrayList<>(); 12 | 13 | int cnt = 0; 14 | 15 | for (int i = 1; i <= N; i++) { 16 | for (int j = 0; j < stages.length; j++) { 17 | if (i == stages[j]) { 18 | cnt++; 19 | } 20 | } 21 | if (cnt == 0) { 22 | fail_rate.add(new double[]{i, 0}); 23 | continue; 24 | } 25 | // 실패율 (클리어 못한 스테이지 번호 수 / 스테이지 도달 유저) 26 | fail_rate.add(new double[]{i, cnt / users}); 27 | users -= cnt; 28 | cnt = 0; 29 | } 30 | 31 | // 정렬하기 32 | fail_rate.sort((a, b) -> Double.compare(b[1], a[1])); 33 | 34 | for (int i = 0; i < fail_rate.size(); i++) { 35 | answer[i] = (int) fail_rate.get(i)[0]; 36 | } 37 | 38 | return answer; 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /programmers/2021 Dev-Matching/로또의 최고 순위와 최저 순위/README.md: -------------------------------------------------------------------------------- 1 | [로또의 최고 순위와 최저 순위](https://programmers.co.kr/learn/courses/30/lessons/77484) 2 | -------------------------------------------------------------------------------- /programmers/2021 Dev-Matching/로또의 최고 순위와 최저 순위/ch_77484.java: -------------------------------------------------------------------------------- 1 | public class ch_77484 { 2 | 3 | class Solution { 4 | public int[] solution(int[] lottos, int[] win_nums) { 5 | int[] answer = new int[2]; 6 | int cnt = 0; 7 | // 모르는 번호 개수 확인 8 | for(int i = 0; i < 6; i++){ 9 | if(lottos[i] == 0) cnt++; 10 | } 11 | 12 | int win = 0; 13 | // 당첨 가능 번호 개수 확인 14 | for(int i = 0; i < 6; i++){ 15 | for(int j = 0; j < 6; j++){ 16 | if(win_nums[i] == lottos[j]) win++; 17 | } 18 | } 19 | 20 | // 등수 계산 21 | answer[0] = (win + cnt) > 1 ? 6 - (win + cnt) + 1 : 6; 22 | answer[1] = win > 1 ? 6 - win + 1 : 6; 23 | return answer; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /programmers/2021 Dev-Matching/로또의 최고 순위와 최저 순위/chan.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] solution(int[] lottos, int[] win_nums) { 3 | int[] answer = new int[2]; 4 | boolean[] isSelected = new boolean[win_nums.length]; 5 | 6 | int cnt = 0; 7 | int correct = 0; 8 | 9 | for (int i = 0; i < lottos.length; i++) { 10 | if (lottos[i] == 0) cnt++; 11 | 12 | for (int j = 0; j < win_nums.length; j++) { 13 | if (isSelected[j]) continue; 14 | if (lottos[i] == win_nums[j]) { 15 | isSelected[j] = true; 16 | correct++; 17 | } 18 | } 19 | } 20 | 21 | int max = cnt + correct; 22 | int min = correct; 23 | 24 | if (max == 0) { 25 | answer[0] = 6; 26 | } else { 27 | answer[0] = 7 - max; 28 | } 29 | if (min <= 1) { 30 | answer[1] = 6; 31 | } else { 32 | answer[1] = 7 - min; 33 | } 34 | 35 | return answer; 36 | } 37 | } -------------------------------------------------------------------------------- /programmers/2021 Dev-Matching/로또의 최고 순위와 최저 순위/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.HashMap; 3 | 4 | class Solution { 5 | public int[] solution(int[] lottos, int[] win_nums) { 6 | int[] answer = new int[2]; 7 | 8 | Arrays.sort(lottos); 9 | Arrays.sort(win_nums); 10 | int ans_cnt = 0; 11 | int wrong_cnt = 0; 12 | for(int i = 0; i < 6; i++){ 13 | if(lottos[i] == 0) { 14 | wrong_cnt++; 15 | continue; 16 | } 17 | for(int j = 0; j < 6; j++){ 18 | if(lottos[i] < win_nums[j]) break; 19 | if(lottos[i] == win_nums[j]) ans_cnt++; 20 | } 21 | } 22 | 23 | HashMap map = new HashMap<>(); 24 | for(int i = 0; i <= 6; i++){ 25 | if(i < 2){ 26 | map.put(i, 6); 27 | }else{ 28 | int a = 7 - i; 29 | map.put(i, a); 30 | } 31 | } 32 | answer[1] = map.get(ans_cnt); 33 | answer[0] = map.get(ans_cnt==6?ans_cnt:ans_cnt+wrong_cnt); 34 | return answer; 35 | } 36 | } -------------------------------------------------------------------------------- /programmers/2021 Dev-Matching/로또의 최고 순위와 최저 순위/oh_로또.java: -------------------------------------------------------------------------------- 1 | package programmers.Lv1; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * @packageName : programmers.Lv1 7 | * @fileName : lotto 8 | * @date : 2022-02-08 9 | * @language : JAVA 10 | * @classification : 11 | * @time_limit : 2sec 12 | * @required_time : 00:40 ~ 01:22 13 | * @submissions : 1 14 | * @description : 15 | **/ 16 | public class oh_로또 { 17 | public int[] solution(int[] lottos, int[] win_nums) { 18 | HashMap map = new HashMap<>(); 19 | int[] answer = new int[2]; 20 | int countRank = 0; 21 | int countZero = 0; 22 | for (int lotto : lottos) { 23 | if (lotto == 0) { 24 | countZero++; 25 | } else { 26 | map.put(lotto, 0); 27 | } 28 | } 29 | for (int i : win_nums) { 30 | if(map.containsKey(i)){ 31 | countRank++; 32 | } 33 | } 34 | 35 | answer[0]=7-countRank-countZero==7?6:7-countRank-countZero; 36 | answer[1]= 7-countRank==7?6:7-countRank; 37 | return answer; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /programmers/2021 KAKAO BLIND RECRUITMENT/메뉴리뉴얼/README.md: -------------------------------------------------------------------------------- 1 | [Programmers 메뉴 리뉴얼](https://programmers.co.kr/learn/courses/30/lessons/72411) -------------------------------------------------------------------------------- /programmers/2021 KAKAO BLIND RECRUITMENT/신규아이디추천/ch.java: -------------------------------------------------------------------------------- 1 | public class ch { 2 | public String solution(String new_id) { 3 | // 1단계 : new_id 모든 대문자를 대응 소문자로 치환 4 | String answer = new_id.toLowerCase(); 5 | // 2단계 : 소문자, 숫자, -, _, .를 제외한 문자 제거 6 | answer = answer.replaceAll("[^a-z0-9-_.]", ""); 7 | // 3단계 : 중복된 .은 하나로 표시 8 | // 하나 이상(+) 9 | answer = answer.replaceAll("\\.+", "."); 10 | // 4단계 : 마침표가 처음이나 끝이면 제거 11 | // 시작점(^) 끝점($) 12 | answer = answer.replaceAll("(^\\.|\\.$)", ""); 13 | // 5단계 : 빈 문자열이면 a대입 14 | if(answer.length() == 0) answer = "a"; 15 | // 6단계 : 길이가 16이상이면 첫 15개 제외한 문자 제거 16 | // 제거 후 마침표 있으면 마침표 제거 17 | if(answer.length() >= 16) answer = answer.substring(0, 15).replaceAll("(\\.$)", ""); 18 | // 7단계 : 길이가 2자 이하라면 마지막 문자를 길이가 3이 될 때까지 반복 19 | if(answer.length() <= 2) { 20 | char ch = answer.charAt(answer.length() - 1); 21 | while(answer.length() < 3) { 22 | answer += ch; 23 | } 24 | } 25 | return answer; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /programmers/2021 KAKAO BLIND RECRUITMENT/신규아이디추천/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public String solution(String new_id) { 3 | String answer = new_id.toLowerCase(); // 1단계 4 | answer = answer.replaceAll("[^a-z0-9-_.]",""); // 2단계. 리턴값으로 answer 받아야 변경 적용 5 | answer = answer.replaceAll("\\.+","."); // 3단계. 특수문자(.)는 역슬래시 두 개 (자바) 6 | answer = answer.replaceAll("(^\\.|\\.$)",""); // 4단계. 처음이나 끝에 위치하는 . 제거 7 | // 5단계 8 | if (answer.length() == 0) answer = "a"; 9 | // 6단계 10 | if (answer.length() >= 16) { 11 | answer = answer.substring(0,15); 12 | answer = answer.replaceAll("(^\\.|\\.$)",""); 13 | } 14 | // 7단계 15 | if (answer.length() <= 2) { 16 | char ch = answer.charAt(answer.length() - 1); 17 | while(answer.length() < 3) answer += ch; 18 | } 19 | return answer; 20 | } 21 | } -------------------------------------------------------------------------------- /programmers/2021 KAKAO BLIND RECRUITMENT/신규아이디추천/haeun.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public String solution (String new_id) { 3 | // 1단계(소문자) 4 | String answer = new_id.toLowerCase() 5 | // 2단계(소문자, 숫자, (-), (_), (.)를 제외한 문자 제거) 6 | .replaceAll("[^a-z0-9-_.]", "") 7 | // 3단계(연속된 .는 .한개로 치환) 8 | .replaceAll("[.]{2,}", ".") 9 | // 4단계(처음 .이나 끝 .은 제거) 10 | .replaceAll("^([.])|([.])$", ""); 11 | 12 | // 5단계(빈 문자열일 때 'a'대입) 13 | if (answer.length() == 0) answer += 'a'; 14 | // 6단계(16자 이상이면 제거, .로 끝나면 .제거) 15 | if (answer.length() >= 16) answer = answer.substring(0, 15).replaceAll("([.])$", ""); 16 | // 7단계(2자 이하면, 마지막 문자 반복) 17 | while (answer.length() < 3) answer += answer.charAt(answer.length()-1); 18 | 19 | // answer 반환 20 | return answer; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /programmers/2021 KAKAO BLIND RECRUITMENT/신규아이디추천/readme.md: -------------------------------------------------------------------------------- 1 | [신규아이디추천](https://programmers.co.kr/learn/courses/30/lessons/72410) 2 | -------------------------------------------------------------------------------- /programmers/2021 카카오 채용연계형 인턴십/숫자 문자열과 영단어/README.md: -------------------------------------------------------------------------------- 1 | [프로그래머스 - 숫자 문자열과 영단어](https://programmers.co.kr/learn/courses/30/lessons/81301) 2 | -------------------------------------------------------------------------------- /programmers/2021 카카오 채용연계형 인턴십/숫자 문자열과 영단어/ch_숫자문자열과영단어.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class ch_숫자문자열과영단어 { 4 | public int solution(String s) { 5 | HashMap map = new HashMap<>(); 6 | map.put("zero", 0); 7 | map.put("one", 1); 8 | map.put("two", 2); 9 | map.put("three", 3); 10 | map.put("four", 4); 11 | map.put("five", 5); 12 | map.put("six", 6); 13 | map.put("seven", 7); 14 | map.put("eight", 8); 15 | map.put("nine", 9); 16 | 17 | String result = ""; 18 | String tmp = ""; 19 | for (int i = 0; i < s.length(); i++) { 20 | char now = s.charAt(i); 21 | if (Character.isDigit(now)) { // 숫자 여부 판단 22 | result += now; 23 | tmp = ""; 24 | } else { 25 | tmp += now; 26 | if (map.get(tmp) != null) { 27 | result += map.get(tmp); 28 | tmp = ""; 29 | } 30 | } 31 | } 32 | return Integer.parseInt(result); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /programmers/2021 카카오 채용연계형 인턴십/숫자 문자열과 영단어/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public int solution(String s) { 3 | String[] numberToString = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; 4 | 5 | StringBuffer answer = new StringBuffer(); 6 | StringBuffer temp = new StringBuffer(); 7 | 8 | for (int i = 0; i < s.length(); i++) { 9 | // 숫자일 때는 반환하기 위해 answer에 추가 10 | if (s.charAt(i) - '0' >= 0 && s.charAt(i) - '0' < 10) { 11 | answer.append(s.charAt(i)); 12 | } 13 | // 숫자가 아닐 때는 연속된 문자열이 영단어에 포함되는지 확인 14 | else { 15 | temp.append(s.charAt(i)); 16 | for (int j = 0; j < numberToString.length; j++) { 17 | // 숫자 문자열이 영단어에 있을 때는 해당하는 숫자를 answer에 추가 18 | if (numberToString[j].equals(temp.toString())) { 19 | answer.append(j); 20 | temp.setLength(0); 21 | } 22 | } 23 | 24 | } 25 | } 26 | // 문자열 형태이므로 숫자로 반환 27 | return Integer.parseInt(answer.toString()); 28 | } 29 | } -------------------------------------------------------------------------------- /programmers/2021 카카오 채용연계형 인턴십/숫자 문자열과 영단어/mj_숫자문자열과영단어.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 문자열에서 영단어를 찾아서 모두 숫자로 바꿔주자 3 | */ 4 | public class D4_숫자문자열과영단어 { 5 | 6 | public static void main(String[] args) { 7 | String s = "one4seveneight"; 8 | int solution = solution(s); 9 | System.out.println(solution); 10 | } 11 | 12 | public static int solution(String s) { 13 | int answer = 0; 14 | // 풀이 1 15 | // s = s.replaceAll("one", "1"); 16 | // s = s.replaceAll("two", "2"); 17 | // s = s.replaceAll("three", "3"); 18 | // s = s.replaceAll("four", "4"); 19 | // s = s.replaceAll("five", "5"); 20 | // s = s.replaceAll("six", "6"); 21 | // s = s.replaceAll("seven", "7"); 22 | // s = s.replaceAll("eight", "8"); 23 | // s = s.replaceAll("nine", "9"); 24 | // s = s.replaceAll("zero", "0"); 25 | 26 | String[] nums = {"1","2","3","4","5","6","7","8","9","0"}; 27 | String[] words = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "zero"}; 28 | 29 | for(int i = 0; i < nums.length; i++){ 30 | s = s.replaceAll(words[i], nums[i]); 31 | } 32 | return Integer.parseInt(s); 33 | } 34 | } -------------------------------------------------------------------------------- /programmers/2021 카카오 채용연계형 인턴십/숫자 문자열과 영단어/oh_숫자_문자열과_영단어.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @packageName : programmers 3 | * @fileName : 숫자 문자열과 영단어 4 | * @date : 2021. 12. 06. 5 | * @language : JAVA 6 | * @classification : String 7 | * @time_limit : 2sec 8 | * @required_time : 00:40 ~ 01:00 9 | * @submissions : 1 10 | * @description 11 | * 12 | **/ 13 | public class oh_숫자_문자열과_영단어 { 14 | static String[] arr ={"zero","one","two","three","four","five","six","seven","eight","nine"}; 15 | 16 | public static void main(String[] args) { 17 | int result = solution("2three45sixseven"); 18 | System.out.println(result); 19 | } 20 | public static int solution(String s) { 21 | for (int i = 0; i < arr.length; i++) { 22 | if(s.contains(arr[i])){ 23 | s=s.replace(arr[i],Integer.toString(i)); 24 | } 25 | } 26 | int answer = Integer.parseInt(s); 27 | return answer; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /programmers/2022 KAKAO BLIND RECRUITMENT/신고 결과 받기/README.md: -------------------------------------------------------------------------------- 1 | [신고 결과 받기](https://programmers.co.kr/learn/courses/30/lessons/92334) 2 | -------------------------------------------------------------------------------- /programmers/2022 KAKAO BLIND RECRUITMENT/신고 결과 받기/ch_92334.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.StringTokenizer; 3 | 4 | public class ch_92334 { 5 | class Solution { 6 | public int[] solution(String[] id_list, String[] report, int k) { 7 | int[] answer = new int[id_list.length]; 8 | StringTokenizer st; 9 | boolean[][] visited = new boolean[id_list.length][id_list.length]; 10 | 11 | // 신고 12 | for(int i = 0; i < report.length; i++){ 13 | st = new StringTokenizer(report[i]); 14 | visited[Arrays.asList(id_list).indexOf(st.nextToken())] 15 | [Arrays.asList(id_list).indexOf(st.nextToken())] = true; 16 | } 17 | 18 | int[] temp = new int[id_list.length]; 19 | // 신고 횟수 처리 20 | for (int i = 0; i < id_list.length; i++) 21 | for (int j = 0; j < id_list.length; j++) 22 | if (visited[j][i]) temp[i]++; 23 | 24 | 25 | // 메일 보낼 사람 처리 26 | for (int i = 0; i < temp.length; i++) { 27 | // 신고받은 횟수가 정리 처분이면 28 | if (temp[i] >= k) { 29 | for (int j = 0; j < id_list.length; j++) 30 | // 정지 처리 메일 보내기 31 | if (visited[j][i]) answer[j]++; 32 | } 33 | } 34 | return answer; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /programmers/2022 KAKAO BLIND RECRUITMENT/신고 결과 받기/chan_92334.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class chan_92334 { 4 | public int[] solution(String[] id_list, String[] report, int k) { 5 | int[] answer = new int[id_list.length]; 6 | Map> idList = new HashMap<>(); 7 | Map count = new HashMap<>(); 8 | for (String id : id_list) { 9 | idList.put(id, new HashSet<>()); 10 | count.put(id, 0); 11 | } 12 | for (String r : report) { 13 | String[] data = r.split(" "); 14 | idList.get(data[1]).add(data[0]); 15 | } 16 | for (String key : idList.keySet()) { 17 | HashSet reportId = idList.get(key); 18 | if (reportId.size() >= k) { 19 | for (String n : reportId) { 20 | count.put(n, count.get(n) + 1); 21 | } 22 | } 23 | } 24 | 25 | for (int i = 0; i < id_list.length; i++) { 26 | answer[i] = count.get(id_list[i]); 27 | } 28 | return answer; 29 | } 30 | } -------------------------------------------------------------------------------- /programmers/Summer,Winter Coding(2019)/멀쩡한 사각형/README.md: -------------------------------------------------------------------------------- 1 | - [멀쩡한 사각형](https://programmers.co.kr/learn/courses/30/lessons/62048) 2 | - level2 3 | -------------------------------------------------------------------------------- /programmers/Summer,Winter Coding(2019)/멀쩡한 사각형/ch.java: -------------------------------------------------------------------------------- 1 | public class ch { 2 | public long solution(int w, int h) { 3 | long answer = 0; 4 | // 최대공약수를 활용 5 | for(int i = 0; i < w; i++) 6 | answer += (Long.valueOf(h) * i) / Long.valueOf(w); 7 | 8 | return answer * 2; 9 | } 10 | 11 | // @Test 12 | // public void 정답() { 13 | // Assert.assertEquals(80, solution(8, 12)); 14 | // Assert.assertEquals(80, solution(12, 8)); 15 | // Assert.assertEquals(12, solution(4, 4)); 16 | // } 17 | } 18 | -------------------------------------------------------------------------------- /programmers/Summer,Winter Coding(2019)/멀쩡한 사각형/chan_62048.java: -------------------------------------------------------------------------------- 1 | class chan_62048 { 2 | public long solution(int w, int h) { 3 | // int 자료형을 long으로 바꿔준 후 계산해야 오차가 안 생김 4 | return (long)w * h - (w + h - gcd(w, h)); 5 | } 6 | 7 | public long gcd(int a, int b) { 8 | long answer = 0; 9 | 10 | long x = (a > b) ? b : a; 11 | for (int i = 1; i <= x; i++) { 12 | if (a % i == 0 && b % i == 0) { 13 | answer = i; 14 | } 15 | } 16 | return answer; 17 | } 18 | } -------------------------------------------------------------------------------- /programmers/Summer,Winter Coding(2019)/멀쩡한 사각형/mj.java: -------------------------------------------------------------------------------- 1 | public class D5_멀쩡한사각형 { 2 | 3 | public static void main(String[] args) { 4 | 5 | int w = 8; 6 | int h = 12; 7 | long res = solution(w, h); 8 | System.out.println(res); 9 | } 10 | 11 | //HxW 사용할 수 있는 정사각형의 개수 12 | static public long solution(int w, int h) { 13 | long answer = 1; 14 | int gcd = 0; 15 | int small = w>h?w:h; 16 | for(int i = small; i > 0; i--){ 17 | if(w%i==0 && h%i==0){ 18 | gcd = i; 19 | break; 20 | } 21 | } 22 | System.out.println(gcd); 23 | answer = w*h-(w+h)+gcd; 24 | return answer; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /programmers/Summer,Winter Coding(~2018)/소수만들기/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class chan { 4 | public int solution(int[] nums) { 5 | 6 | comb(nums, 0, 0); 7 | 8 | return answer; 9 | } 10 | static int answer = 0; 11 | static int[] numbers = new int[3]; 12 | public void comb(int[] nums, int cnt, int start) { 13 | if (cnt == 3) { 14 | int sum = 0; 15 | for (int i = 0; i < numbers.length; i++) { 16 | sum += numbers[i]; 17 | } 18 | if (isPrime(sum)) { 19 | answer++; 20 | } 21 | return; 22 | } 23 | 24 | for (int i = start; i < nums.length; i++) { 25 | numbers[cnt] = nums[i]; 26 | 27 | comb(nums, cnt + 1, i + 1); 28 | } 29 | } 30 | 31 | public boolean isPrime(int sum) { 32 | boolean flag = false; 33 | for (int i = 2; i < sum; i++) { 34 | if (sum % i == 0) flag = true; 35 | } 36 | 37 | if (flag) return false; 38 | return true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /programmers/Summer,Winter Coding(~2018)/소수만들기/mj.java: -------------------------------------------------------------------------------- 1 | public class D8_소수만들기 { 2 | 3 | static int ans; 4 | public static void main(String[] args) { 5 | int[] nums = new int[]{1,2,3,4}; 6 | ans = 0; 7 | int res = solution(nums); 8 | System.out.println(res); 9 | 10 | } 11 | 12 | static public int solution(int[] nums) { 13 | 14 | // combination 15 | comb(0, 0, 0, nums); 16 | 17 | 18 | return ans; 19 | } 20 | 21 | private static void comb(int start, int cnt, int sum, int[] nums) { 22 | 23 | if(cnt >= 3){ 24 | boolean isS = true; 25 | for (int i = 2; i < sum; i++) { 26 | if(1 == sum || i == sum) break; 27 | if(sum%i == 0){ 28 | isS = false; 29 | break; 30 | } 31 | } 32 | 33 | if(isS) ans++; 34 | return; 35 | } 36 | 37 | for (int i = start; i < nums.length; i++) { 38 | comb(i+1, cnt+1, sum+nums[i], nums); 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /programmers/스택큐/기능개발/ch.java: -------------------------------------------------------------------------------- 1 | package Programmers; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class 기능개발 { 7 | private static int[] solution(int[] progresses, int[] speeds) { 8 | List anslist = new ArrayList<>(); 9 | int[] daycnt = new int[100]; 10 | int day = 0; 11 | 12 | for (int i = 0; i < progresses.length; i++) { 13 | while (progresses[i] + (day * speeds[i]) < 100) { 14 | day += 1; 15 | } 16 | daycnt[day] += 1; 17 | } 18 | 19 | for (int i = 0; i < daycnt.length; i++) { 20 | if (daycnt[i] == 0) { 21 | continue; 22 | } else { 23 | anslist.add(daycnt[i]); 24 | } 25 | } 26 | int[] answer = new int[anslist.size()]; 27 | 28 | for (int i = 0; i < anslist.size(); i++) { 29 | answer[i] = anslist.get(i); 30 | } 31 | return answer; 32 | } 33 | public static void main(String[] args) { 34 | int[] progresses = {95, 90, 99, 99, 80, 99}; 35 | int[] speeds = {1, 1, 1, 1, 1, 1}; 36 | solution(progresses, speeds); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /programmers/스택큐/기능개발/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Queue; 3 | import java.util.ArrayList; 4 | class chan { 5 | public int[] solution(int[] progresses, int[] speeds) { 6 | Queue queue = new LinkedList<>(); 7 | ArrayList list = new ArrayList<>(); 8 | for (int i = 0; i < progresses.length; i++) { 9 | int left = 100 - progresses[i]; 10 | int funcDays = left / speeds[i]; 11 | if (left % speeds[i] != 0) funcDays += 1; 12 | queue.offer(funcDays); 13 | } 14 | 15 | while(!queue.isEmpty()) { 16 | int cur = queue.poll(); 17 | int howmany = 1; 18 | while (!queue.isEmpty() && queue.peek() <= cur) { 19 | queue.poll(); 20 | howmany++; 21 | } 22 | 23 | list.add(howmany); 24 | } 25 | int[] answer = new int[list.size()]; 26 | for (int i = 0; i < list.size(); i++) { 27 | answer[i] = list.get(i); 28 | } 29 | return answer; 30 | } 31 | } -------------------------------------------------------------------------------- /programmers/스택큐/기능개발/oh.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.LinkedList; 3 | import java.util.Queue; 4 | 5 | public class oh { 6 | public static void main(String[] args) { 7 | solution(new int[]{95,90,99,99,80,99}, new int[]{1,1,1,1,1,1}).stream().forEach(Object-> System.out.println(Object)); 8 | } 9 | public static ArrayList solution(int[] progresses, int[] speeds) { 10 | Queue que = new LinkedList(); 11 | for (int i = 0; i < progresses.length; i++) { 12 | int value=(100-progresses[i])%speeds[i]==0?(100-progresses[i])/speeds[i]:(100-progresses[i])/speeds[i]+1; 13 | que.add(value); 14 | } 15 | int count =1; 16 | ArrayList answer = new ArrayList<>(); 17 | int result =que.poll(); 18 | while (!que.isEmpty()){ 19 | if(que.peek()<=result){ 20 | count++; 21 | que.poll(); 22 | } 23 | else{ 24 | answer.add(count); 25 | count=1; 26 | result=que.poll(); 27 | } 28 | } 29 | answer.add(count); 30 | return answer; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /programmers/스택큐/프린터/ch_프린터.java: -------------------------------------------------------------------------------- 1 | import java.util.Collections; 2 | import java.util.PriorityQueue; 3 | 4 | public class ch_프린터 { 5 | public static void main(String[] args) { 6 | int[] priorities = {1,1,9,1,1,1}; 7 | int location = 0; 8 | System.out.println(solution(priorities, location)); 9 | } 10 | 11 | public static int solution(int[] priorities, int location) { 12 | int answer = 1; 13 | PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); 14 | 15 | for(int i = 0; i < priorities.length; i++){ 16 | pq.add(priorities[i]); 17 | } 18 | 19 | while(!pq.isEmpty()){ 20 | for(int i = 0; i < priorities.length; i++){ 21 | if(pq.peek() == priorities[i]){ 22 | if(i == location){ 23 | return answer; 24 | } 25 | answer++; 26 | pq.poll(); 27 | } 28 | } 29 | } 30 | 31 | return answer; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌1/내적/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public int solution(int[] a, int[] b) { 3 | int answer = 0; 4 | 5 | for (int i = 0; i < a.length; i++) { 6 | answer += (a[i] * b[i]); 7 | } 8 | 9 | return answer; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌1/내적/mj.java: -------------------------------------------------------------------------------- 1 | public class D8_내적 { 2 | 3 | public static void main(String[] args) { 4 | int[] a = {1,2,3,4}; 5 | int[] b = {-3,-1,0,2}; 6 | int ans = solution(a, b); 7 | System.out.println(ans); 8 | } 9 | 10 | static public int solution(int[] a, int[] b) { 11 | int answer = 0; 12 | for (int i = 0; i < a.length; i++) { 13 | answer += a[i]*b[i]; 14 | } 15 | return answer; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌2/약수의 개수와 덧셈/ch_약수의개수와덧셈.java: -------------------------------------------------------------------------------- 1 | class ch_약수의개수와덧셈 { 2 | public int solution(int left, int right) { 3 | int answer = 0; 4 | for(int i = left; i <= right; i++){ 5 | int primeN = getPrimeNum(i); 6 | if(primeN % 2 == 0){ 7 | answer += i; 8 | }else { 9 | answer -= i; 10 | } 11 | } 12 | return answer; 13 | } 14 | 15 | public int getPrimeNum(int N){ 16 | int primeCnt = 1; 17 | 18 | for(int i = 1; i < N; i++){ 19 | if(N % i == 0) primeCnt++; 20 | } 21 | return primeCnt; 22 | } 23 | } -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌2/음양더하기/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public int solution(int[] absolutes, boolean[] signs) { 3 | int answer = 0; 4 | 5 | for (int i = 0; i < signs.length; i++) { 6 | int num = absolutes[i]; 7 | if (!signs[i]) { 8 | num *= -1; 9 | } 10 | answer += num; 11 | } 12 | 13 | return answer; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌2/음양더하기/mj.java: -------------------------------------------------------------------------------- 1 | public class D8_음양더하기 { 2 | 3 | public static void main(String[] args) { 4 | int[] absolutes = {4,7,12}; 5 | boolean[] signs = {true,false,true}; 6 | 7 | int ans = solution(absolutes, signs); 8 | System.out.println(ans); 9 | 10 | } 11 | 12 | static public int solution(int[] absolutes, boolean[] signs) { 13 | int answer = 0; 14 | for (int i = 0; i < absolutes.length; i++) { 15 | int k = absolutes[i]; 16 | if(!signs[i]) k *= -1; 17 | answer += k; 18 | } 19 | 20 | return answer; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌3/없는숫자더하기/README.md: -------------------------------------------------------------------------------- 1 | [없는 숫자 더하기](https://programmers.co.kr/learn/courses/30/lessons/86051) 2 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌3/없는숫자더하기/ch.java: -------------------------------------------------------------------------------- 1 | public class ch { 2 | public int solution(int[] numbers) { 3 | int answer = 45; 4 | 5 | for(int i = 0; i < numbers.length; i++){ 6 | answer -= numbers[i]; 7 | } 8 | return answer; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌3/없는숫자더하기/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public int solution(int[] numbers) { 3 | int answer = 0; 4 | 5 | boolean[] isExist = new boolean[10]; 6 | 7 | for (int i = 0; i < numbers.length; i++) { 8 | isExist[numbers[i]] = true; 9 | } 10 | 11 | for (int i = 0; i < isExist.length; i++) { 12 | if (!isExist[i]) answer += i; 13 | } 14 | 15 | return answer; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /programmers/월간코드챌린지시즌3/없는숫자더하기/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class D7_없는숫자더하기 { 4 | 5 | public static void main(String[] args) { 6 | 7 | int[] numbers = {1,2,3,4,6,7,8,0}; 8 | int ans = solution(numbers); 9 | System.out.println(ans); 10 | 11 | } 12 | 13 | public static int solution(int[] numbers) { 14 | int answer = 0; 15 | // 검색을 위해 16 | HashMap map = new HashMap<>(); 17 | for (int i = 0; i < numbers.length; i++) { 18 | map.put(numbers[i], numbers[i]); 19 | } 20 | 21 | for (int i = 0; i < 10; i++) { 22 | // key 존재 여부에 따라 없는 숫자 더하기 23 | if(!map.containsKey(i)) answer += i; 24 | } 25 | 26 | return answer; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /programmers/찾아라 프로그래밍 마에스터/README.md: -------------------------------------------------------------------------------- 1 | [level1 폰켓몬](https://programmers.co.kr/learn/courses/30/lessons/1845) 2 | -------------------------------------------------------------------------------- /programmers/찾아라 프로그래밍 마에스터/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | /** 4 | N마리의 포켓몬 중에서 N/2마리의 포켓몬을 선택하자 5 | 최대한 많은 종류의 포켓몬을 얻고 싶다. 6 | */ 7 | public class D11_포켓몬 { 8 | 9 | public static void main(String[] args) { 10 | int[] nums = {3,3,3,2,2,2}; 11 | int solution = solution(nums); 12 | System.out.println(solution); 13 | 14 | } 15 | 16 | /** 17 | * 18 | * @param nums 포켓몬의 종류 번호가 담긴 배열. 중복 가능 19 | * @return 선택할 수 있는 포켓몬 종류 개수의 최댓값 20 | */ 21 | private static int solution(int[] nums) { 22 | int answer = 0; 23 | int count = nums.length/2; 24 | // 최대 count의 포켓몬의 종류를 가져갈 수 있다. 25 | // 가져갈 수 있는 포켓몬의 종류를 최대한으로 가져가고 싶다. 26 | HashMap hm = new HashMap<>(); 27 | for (int num : nums) { 28 | if(hm.containsKey(num)){ 29 | int cnt = hm.get(num); 30 | hm.replace(num, cnt+1); 31 | }else{ 32 | hm.put(num, 1); 33 | } 34 | } 35 | 36 | // 만약 hm의 사이즈가 count보다 크면 count 만큼의 종류를 가져갈 수 있음 37 | if (count <= hm.size()){ 38 | answer = count; 39 | }else { 40 | // 아니면 hm의 사이즈만큼 가져갈 수 있음 41 | answer = hm.size(); 42 | } 43 | 44 | return answer; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programmers/찾아라 프로그래밍 마에스터/폰켓몬/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public int solution(int[] nums) { 3 | int answer = 0; 4 | int pickNum = nums.length / 2; 5 | 6 | System.out.println(pickNum); 7 | 8 | boolean[] type = new boolean[200001]; 9 | 10 | for (int i = 0; i < nums.length; i++) { 11 | type[nums[i]] = true; 12 | } 13 | 14 | // true 개수 세기 15 | int cnt = 0; 16 | for (int i = 1; i < type.length; i++) { 17 | if (type[i]) cnt++; 18 | } 19 | 20 | System.out.println(cnt); 21 | 22 | if (cnt <= pickNum) answer = cnt; 23 | else answer = pickNum; 24 | 25 | return answer; 26 | } 27 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/124 나라의 숫자/ch_12899.java: -------------------------------------------------------------------------------- 1 | public class ch_12899 { 2 | public String solution(int n) { 3 | String[] num = {"4", "1", "2"}; 4 | String answer = ""; 5 | 6 | while (n > 0) { 7 | answer = num[n % 3] + answer; 8 | // 3으로 나누어 떨어질 땐 -1 9 | n = (n - 1) / 3; 10 | } 11 | return answer; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/124 나라의 숫자/chan.java: -------------------------------------------------------------------------------- 1 | class chan { 2 | public String solution(int n) { 3 | String answer = ""; 4 | int k = 0; 5 | 6 | while (n > 0) { 7 | k = n % 3; //나머지 - 자릿수 (낮은자리부터) 8 | n = n / 3; //몫 - 다음루프의 피제수 9 | if (k == 0) { 10 | n = n-1; //자리올림을 안 하는 효과 11 | k = 4; 12 | } 13 | answer = k + answer; 14 | } 15 | return answer; 16 | } 17 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/124 나라의 숫자/mj.java: -------------------------------------------------------------------------------- 1 | public class D6_124나라의숫자 { 2 | 3 | public static void main(String[] args) { 4 | int n = 4; 5 | String ans = solution(n); 6 | System.out.println(ans); 7 | } 8 | 9 | static public String solution(int n) { 10 | StringBuilder answer = new StringBuilder(); 11 | int[] Ns = {1,2,4}; 12 | 13 | while(true){ 14 | if(n-1 < 3){ 15 | answer.insert(0, Ns[n-1]); 16 | break; 17 | } 18 | answer.insert(0, Ns[(n-1)%3]); 19 | // 더 큰자리가 나온다면 20 | n = (n-1)/3; 21 | 22 | } 23 | return answer.toString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/2017팁스타운/짝지어제거하기/README.md: -------------------------------------------------------------------------------- 1 | [짝지어제거하기](https://programmers.co.kr/learn/courses/30/lessons/12973) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/2017팁스타운/짝지어제거하기/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class chan 5 | { 6 | public int solution(String s) 7 | { 8 | int answer = 0; 9 | Stack stack = new Stack<>(); 10 | 11 | for (int i = 0; i < s.length(); i++) { 12 | if (stack.isEmpty()) stack.push(s.charAt(i)); 13 | else if (stack.peek() == s.charAt(i)) stack.pop(); 14 | else stack.push(s.charAt(i)); 15 | } 16 | 17 | if (stack.size() == 0) answer = 1; 18 | 19 | return answer; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/2017팁스타운/짝지어제거하기/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | public class D9_짝지어제거하기 { 4 | 5 | public static void main(String[] args) { 6 | String s = "baabaa"; 7 | int sol = solution(s); 8 | System.out.println(sol); 9 | } 10 | 11 | static public int solution(String s) 12 | { 13 | int answer = 0; 14 | Stack stack = new Stack<>(); 15 | char[] chars = s.toCharArray(); 16 | for (int i = 0; i < chars.length; i++) { 17 | if(stack.isEmpty() || stack.peek() != chars[i]) 18 | stack.push(chars[i]); 19 | else if(stack.peek() == chars[i]) 20 | stack.pop(); 21 | } 22 | if (stack.isEmpty()) answer = 1; 23 | 24 | 25 | return answer; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/완전탐색/모의고사/ch.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Arrays; 3 | 4 | public class ch { 5 | public int[] solution(int[] answers) { 6 | int[] first = {1,2,3,4,5}; 7 | int[] second = {2,1,2,3,2,4,2,5}; 8 | int[] third = {3,3,1,1,2,2,4,4,5,5}; 9 | int[] scores = {0,0,0}; 10 | 11 | for(int i = 0; i < answers.length; i++){ 12 | if(first[i % 5] == answers[i]) scores[0]++; 13 | if(second[i % 8] == answers[i]) scores[1]++; 14 | if(third[i % 10] == answers[i]) scores[2]++; 15 | } 16 | ArrayList list = new ArrayList(); 17 | 18 | int[] arr = new int[scores.length]; 19 | for(int i = 0; i < scores.length; i++){ 20 | arr[i] = scores[i]; 21 | } 22 | 23 | Arrays.sort(arr); 24 | 25 | for(int i = 0; i < arr.length; i++){ 26 | if(scores[i] == arr[2]){ 27 | list.add(i+1); 28 | } 29 | } 30 | 31 | int[] answer = new int[list.size()]; 32 | for(int i = 0; i < list.size(); i++){ 33 | answer[i] = list.get(i); 34 | } 35 | 36 | return answer; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/완전탐색/카펫/ch.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class Carpet { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int[] answer = new int[2]; 8 | int brown = sc.nextInt(); 9 | int yellow = sc.nextInt(); 10 | answer = solution(brown, yellow); 11 | 12 | System.out.println(Arrays.toString(answer)); 13 | } 14 | 15 | private static int[] solution(int brown, int yellow) { 16 | int[] answer = new int[2]; 17 | int size = brown + yellow; 18 | 19 | for(int i = 1; i <= size; i++) { 20 | int y = i; //세로 21 | int x = size / y; //가로 22 | 23 | //가로는 세로보다 길거나 세로와 같다 24 | if( y > x ) continue; 25 | 26 | if((x - 2) * (y - 2) == yellow) { 27 | answer[0] = x; 28 | answer[1] = y; 29 | return answer; 30 | } 31 | } 32 | return answer; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/완전탐색/카펫/chan.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class chan { 5 | public int[] solution(int brown, int yellow) { 6 | int[] answer = new int[2]; 7 | int carpet = brown + yellow; 8 | ArrayList list = new ArrayList<>(); 9 | // 카펫 격자 수의 약수 구하기 10 | for (int i = 1; i <= carpet; i++) { 11 | if (carpet % i == 0) { 12 | list.add(i); 13 | } 14 | } 15 | 16 | while (true) { 17 | // 카펫 격자수 약수 리스트 중에서 가장 차이가 적은 두 개를 가로 세로로 저장하기 18 | if (list.size() % 2 == 0) { 19 | answer[0] = list.get(list.size() / 2); 20 | answer[1] = list.get(list.size() / 2 - 1); 21 | } else { 22 | answer[0] = answer[1] = list.get(list.size() / 2); 23 | } 24 | // 예외처리 - (테케 4,6,7실패) 카펫의 갈색줄 테두리 한 줄인지 확인하기 25 | if ((answer[0] - 2) * (answer[1] - 2) == yellow) break; 26 | else { 27 | // 테두리 갈색줄이 한 줄이 아닐 때는 선택한 약수값 삭제하기 28 | if (list.size() % 2 == 0) { 29 | list.remove(list.size() / 2); 30 | list.remove(list.size() / 2); 31 | } else { 32 | list.remove(list.size() / 2); 33 | } 34 | } 35 | } 36 | 37 | return answer; 38 | } 39 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/완전탐색/카펫/haeun.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class Programmers_lv2_카펫 { 5 | private static int[] answer; 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int brown = sc.nextInt(); 10 | int yellow = sc.nextInt(); 11 | solution(brown, yellow); 12 | // 출력 13 | System.out.println(Arrays.toString(answer)); 14 | sc.close(); 15 | } 16 | 17 | public static int[] solution(int brown, int yellow) { 18 | int width = 0; 19 | int height = 0; 20 | int sum = brown + yellow; 21 | 22 | // 가로*세로 = brown + yellow 23 | for (int i = 3; i < sum / 2; i++) { 24 | if (sum % i == 0) { 25 | width = sum / i; 26 | height = i; 27 | // 가로*2 + 세로*2 - 4 = brown 28 | if (width*2 + height*2 - 4 == brown) break; 29 | } 30 | } 31 | answer = new int[]{width, height}; 32 | return answer; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/완전탐색/카펫/ohj.java: -------------------------------------------------------------------------------- 1 | package programmers; 2 | 3 | import java.time.Year; 4 | import java.util.ArrayList; 5 | import java.util.Scanner; 6 | 7 | public class 카펫 { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | 12 | int yellow = 2; 13 | 14 | 15 | int brown = 10; 16 | 17 | int sum = brown + yellow; 18 | ArrayList arr = new ArrayList<>(); 19 | for (int i = 1; i <= sum; i++) { 20 | if (sum % i == 0) { 21 | arr.add(i); 22 | } 23 | } 24 | for (int i = arr.size() - 1; i >= 0; i--) { 25 | int row = arr.get(i); 26 | int col = sum / row; 27 | if (row < col) continue; 28 | 29 | if (row - 2 < 0 && col - 2 < 0) { 30 | continue; 31 | } else if((row-2)*(col-2)==yellow) { 32 | System.out.print(row); 33 | System.out.print(col); 34 | 35 | } 36 | 37 | } 38 | } 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/이분탐색/입국심사/ch_입국심사.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class ch_입국심사 { 4 | public long solution(int n, int[] times) { 5 | long answer = 0; 6 | Arrays.sort(times); 7 | long left = 0; 8 | long right = (long) n * times[times.length - 1]; 9 | while(left <= right) { 10 | long mid = (left + right) / 2; 11 | long sum = 0; 12 | for(int i = 0; i < times.length; i++) { 13 | sum += mid / times[i]; 14 | } 15 | if(sum < n) { 16 | left = mid + 1; 17 | }else { 18 | right = mid - 1; 19 | answer = mid; 20 | } 21 | } 22 | return answer; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/이분탐색/입국심사/chan.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class chan { 4 | public long solution(int n, int[] times) { 5 | long answer = 0; // 모든 사람이 심사 받는데 걸리는 시간의 최솟값 6 | Arrays.sort(times); // 시간이 짧은 심사관순으로 정렬 7 | long start = times[0]; // 입국 심사 기다리는 사람 최소 1명일 때 걸리는 시간 8 | long end = (long)times[times.length - 1] * n; 9 | // 이분탐색 10 | while (start <= end) { 11 | long mid = (start + end) / 2; 12 | long count = 0; // 심사관이 입국 심사 한 사람 수 13 | for (int i = 0; i < times.length; i++) { 14 | count += mid / times[i]; 15 | } 16 | if (count < n) { // 입국심사 해야 할 사람 수보다 조금했을 때 17 | start = mid + 1; // 탐색하는 시간 늘리기 18 | } else { // 입국심사 해야 할 사람 수보다 많이 했을 때 19 | end = mid - 1; // 탐색하는 시간 줄이기 20 | } 21 | } 22 | return start; 23 | } 24 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/이분탐색/입국심사/haeun_입국심사.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class programmers_lv3_입국심사 { 4 | 5 | public static void main(String[] args) { 6 | System.out.println(solution(6, new int[] {7, 10})); 7 | } 8 | 9 | public static long solution(int n, int[] times) { 10 | long answer = Long.MAX_VALUE; 11 | 12 | // 오름차순 정렬 13 | Arrays.sort(times); 14 | long left = 1; 15 | // 가장 늦게 끝나는 시간 16 | long right = (long) times[times.length-1] * n; 17 | 18 | while (left <= right) { 19 | // 이분탐색을 위한 mid 값 20 | long mid = (left + right) / 2; 21 | // 해당 시간에 각 심사대의 최대 심사 수의 합을 구할 변수 22 | long count = 0; 23 | 24 | // times 배열을 순회하면서 25 | for (int i = 0; i < times.length; i++) { 26 | // 해당 시간의 심사 수를 계산하여 count 변수에 더하기 27 | count += mid / times[i]; 28 | } 29 | 30 | // 만일 count 변수가 사람 수 n 값보다 같거나 크다면 31 | // answer 변수와 mid 변수 중에 작은 값을 answer 변수에 저장 32 | // mid의 왼쪽을 탐색 33 | if (count >= n) { 34 | answer = Math.min(answer, mid); 35 | right = mid - 1; 36 | } 37 | // 만일 count 변수가 사람 수 n 값보다 작다면 38 | // mid의 오른쪽을 탐색 39 | else left = mid + 1; 40 | } 41 | return answer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/이분탐색/입국심사/oh_입국심사.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class oh_입국심사 { 4 | public long solution(int n, int[] times) { 5 | Arrays.sort(times); 6 | long answer = 0; 7 | long min = 0; 8 | long max = (long) times[times.length - 1]*n; 9 | 10 | while (min <= max) { 11 | long mid = (max + min) / 2; 12 | long sum = 0; 13 | 14 | for (int time : times) { 15 | sum += mid / time; 16 | } 17 | 18 | if (sum < n) { 19 | min = mid + 1; 20 | answer = min; 21 | } else { 22 | max = mid - 1; 23 | } 24 | 25 | } 26 | return answer; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/이분탐색/입국심사/readme.md: -------------------------------------------------------------------------------- 1 | [🛬입국심사](https://programmers.co.kr/learn/courses/30/lessons/43238) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/정렬/K번째수/README.md: -------------------------------------------------------------------------------- 1 | [K번째수](https://programmers.co.kr/learn/courses/30/lessons/42748) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/정렬/K번째수/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class D9_K번째수 { 4 | 5 | public static void main(String[] args) { 6 | int[] array = {1, 5, 2, 6, 3, 7, 4}; 7 | int[][] commands = {{2, 5, 3}, {4, 4, 1}, {1, 7, 3}}; 8 | 9 | int[] sol = solution(array, commands); 10 | System.out.println(Arrays.toString(sol)); 11 | } 12 | 13 | static public int[] solution(int[] array, int[][] commands) { 14 | int[] answer = new int[commands.length]; 15 | 16 | for (int j = 0; j < commands.length; j++) { 17 | int[] command = commands[j]; 18 | int start = command[0]-1; // 1 19 | int end = command[1]-1; // 4 20 | int cnt = command[2]-1; // 2 21 | 22 | int[] newArr = new int[end-start+1]; 23 | int k = 0; 24 | for (int i = start; i <= end ; i++) { 25 | newArr[k++] = array[i]; 26 | } 27 | // 5,2,6,3 -> 2,3,5,6 28 | Arrays.sort(newArr); 29 | answer[j] = newArr[cnt]; 30 | } 31 | 32 | return answer; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/탐욕법(Greedy)/체육복/README.md: -------------------------------------------------------------------------------- 1 | [Programmers 체육복](https://programmers.co.kr/learn/courses/30/lessons/42862) -------------------------------------------------------------------------------- /programmers/코딩테스트연습/탐욕법(Greedy)/체육복/ch.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class ch { 4 | public int solution(int n, int[] lost, int[] reserve) { 5 | int answer = n - lost.length; 6 | 7 | Arrays.sort(lost); 8 | Arrays.sort(reserve); 9 | 10 | 11 | for(int i = 0; i < lost.length; i++){ 12 | for(int j = 0; j < reserve.length; j++){ 13 | // 여벌 학생 도난당한 경우 14 | if(lost[i] == reserve[j]) { 15 | answer++; 16 | lost[i] = -1; 17 | reserve[j] = -1; 18 | break; 19 | } 20 | } 21 | } 22 | 23 | for(int i = 0; i < lost.length; i++){ 24 | for(int j = 0; j < reserve.length; j++){ 25 | // 체육복 빌려주는 경우 26 | if((lost[i] - 1 == reserve[j]) || (lost[i] + 1 == reserve[j])) { 27 | answer++; 28 | reserve[j] = -1; 29 | break; 30 | } 31 | } 32 | } 33 | 34 | 35 | return answer; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42576. 완주하지못한 선수/ch_완주하지못한선수.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class ch_완주하지못한선수 { 4 | private static String solution(String[] participant, String[] completions) { 5 | String ans = ""; 6 | HashMap hash = new HashMap<>(); 7 | for (String p : participant) { 8 | hash.put(p, hash.getOrDefault(p, 0) + 1); 9 | } 10 | for (String c : completions) { 11 | hash.put(c, hash.get(c) - 1); 12 | } 13 | for (String k : hash.keySet()) { 14 | if (hash.get(k) == 1) ans = k; 15 | } 16 | 17 | return ans; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42576. 완주하지못한 선수/chan_42576.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | class chan_42576 { 4 | public String solution(String[] participant, String[] completion) { 5 | String answer = ""; 6 | /** 7 | * HashMap은 Map Collection중 하나 8 | * Map은 키-값으로 저장 9 | * - 키는 중복 X 10 | * - 값은 중복 O 11 | */ 12 | HashMap hm = new HashMap<> (); 13 | for(String par : participant) 14 | hm.put(par, hm.getOrDefault(par, 0) + 1); 15 | 16 | for(String com : completion) 17 | hm.put(com, hm.get(com) - 1); 18 | 19 | for(String key : hm.keySet()) 20 | if(hm.get(key) != 0) 21 | answer = key; 22 | 23 | return answer; 24 | } 25 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42576. 완주하지못한 선수/haeun_완주하지못한선수.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class programmers_lv1_완주하지못한선수 { 4 | 5 | public static void main(String[] args) { 6 | System.out.println(solution(new String[] {"leo", "kiki", "eden"}, new String[] {"eden", "kiki"})); 7 | } 8 | 9 | public static String solution(String[] participant, String[] completion) { 10 | String answer = ""; 11 | HashMap hash = new HashMap<>(); 12 | 13 | // 참가자 명단 14 | for (String p : participant) { 15 | // 이름 중복 X 16 | if (hash.get(p) == null) hash.put(p, 1); 17 | // 이름 중복 O 18 | else hash.put(p, hash.get(p)+1); 19 | } 20 | 21 | // 완주자 명단 22 | for (String p : completion) { 23 | // 완주 O 24 | hash.put(p, hash.get(p)-1); 25 | } 26 | 27 | // 완주하지 못한 참가자 28 | for (String p : participant) { 29 | if (hash.get(p) != 0) answer = p; 30 | } 31 | 32 | return answer; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42576. 완주하지못한 선수/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Set; 3 | 4 | public class D8_완주하지못한선수 { 5 | 6 | public static void main(String[] args) { 7 | String[] participant = {"leo", "kiki", "eden"}; 8 | String[] completion = {"eden", "kiki"}; 9 | 10 | String solution = solution(participant, completion); 11 | System.out.println(solution); 12 | } 13 | 14 | static public String solution(String[] participant, String[] completion) { 15 | String answer = ""; 16 | HashMap m = new HashMap<>(); 17 | for (int i = 0; i < participant.length; i++) { 18 | if(m.containsKey(participant[i])){ 19 | int k = m.get(participant[i]); 20 | m.replace(participant[i], k+1); 21 | }else { 22 | m.put(participant[i], 1); 23 | } 24 | } 25 | 26 | for (String s : completion) { 27 | if(m.containsKey(s)){ 28 | int k = m.get(s); 29 | if(k == 1){ 30 | m.remove(s); 31 | }else{ 32 | m.replace(s,k-1); 33 | } 34 | } 35 | } 36 | 37 | Set ans = m.keySet(); 38 | answer = (String) (ans.toArray()[0]); 39 | return answer; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42576. 완주하지못한 선수/oh.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | 4 | public class oh { 5 | public static void main(String[] args) { 6 | String result = solution(new String[]{"mislav","mislav", "stanko","stanko", "mislav", "ana", "ana"}, new String[]{"mislav","stanko","stanko", "ana", "mislav", "ana"}); 7 | System.out.println(result); 8 | } 9 | 10 | public static String solution(String[] participant, String[] completion) { 11 | String answer = ""; 12 | Map map = new HashMap(); 13 | for (String s : participant) { 14 | 15 | map.put(s,map.getOrDefault(s,0)+1); 16 | 17 | } 18 | for (String s : completion) { 19 | map.put(s,map.get(s)-1); 20 | } 21 | for (String s : map.keySet()) { 22 | if(map.get(s)!=0){ 23 | answer=s; 24 | } 25 | } 26 | return answer; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42576. 완주하지못한 선수/readme.md: -------------------------------------------------------------------------------- 1 | [프로그래머스 - 42576. 완주하지못한선수](https://programmers.co.kr/learn/courses/30/lessons/42576) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42577. 전화번호 목록/README.md: -------------------------------------------------------------------------------- 1 | [프로그래머스 - 42577. 전화번호 목록](https://programmers.co.kr/learn/courses/30/lessons/42577) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42577. 전화번호 목록/ch_전화번호목록.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class ch_전화번호목록 { 4 | public boolean solution(String[] phone_book) { 5 | HashMap hash = new HashMap<>(); 6 | 7 | for(int i = 0; i < phone_book.length; i++){ 8 | hash.put(phone_book[i], i); 9 | } 10 | 11 | for(int i = 0; i < phone_book.length; i++){ 12 | for(int j = 0; j < phone_book[i].length(); j++){ 13 | if(hash.containsKey(phone_book[i].substring(0, j))){ 14 | return false; 15 | } 16 | } 17 | } 18 | return true; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42577. 전화번호 목록/chan_42577.java: -------------------------------------------------------------------------------- 1 | public class chan_42577 { 2 | public boolean solution(String[] phone_book) { 3 | boolean answer = true; 4 | 5 | for(int i = 0; i < phone_book.length; i++){ 6 | for(int j = 0; j < phone_book.length; j++) { 7 | if(i==j) 8 | continue; 9 | if(phone_book[i].startsWith(phone_book[j])) 10 | return false; 11 | } 12 | } 13 | 14 | return answer; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42577. 전화번호 목록/haeun_전화번호목록.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.HashSet; 3 | 4 | public class programmers_lv2_전화번호목록 { 5 | 6 | public static void main(String[] args) { 7 | System.out.println(solution(new String[] {"119", "97674223", "1195524421"})); 8 | } 9 | 10 | public static boolean solution(String[] phone_book) { 11 | HashSet hash = new HashSet<>(); 12 | // 정렬 13 | Arrays.sort(phone_book); 14 | 15 | for (String phone : phone_book) { 16 | hash.add(phone); 17 | 18 | // 앞에서부터 번호를 하나씩 늘려가면서 접두사가 있는지 판단 19 | for (int i = 0; i < phone.length(); i++) { 20 | // 접두사 O 21 | if (hash.contains(phone.substring(0, i))) { 22 | return false; 23 | } 24 | } 25 | } 26 | // 접두사 X 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42577. 전화번호 목록/oh.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | 4 | public class oh { 5 | public static void main(String[] args) { 6 | boolean answer = solution(new String[]{"123","456","789"}); 7 | System.out.println(answer); 8 | } 9 | public static boolean solution(String[] phone_book) { 10 | Arrays.sort(phone_book); 11 | for (int i = 0; i < phone_book.length - 1; i++){ 12 | if (phone_book[i + 1].startsWith(phone_book[i])){ 13 | return false; 14 | } 15 | } 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42578.위장/ch_위장.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class ch_위장 { 4 | public int solution(String[][] clothes) { 5 | int answer = 1; 6 | HashMap hash = new HashMap(); 7 | 8 | for(int i =0; i clomap = new HashMap(); 12 | 13 | for(int i = 0; i < clothes.length; i++) { 14 | if(clomap.containsKey(clothes[i][1])) 15 | value = clomap.get(clothes[i][1]) + 1; 16 | clomap.put(clothes[i][1], value); 17 | value = 1; 18 | } 19 | 20 | Collection values = clomap.values(); 21 | for(Integer a : values){ 22 | combination *= (a + 1); 23 | } 24 | answer = combination - 1; 25 | 26 | return answer; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42578.위장/haeun_위장.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class programmers_lv2_위장 { 4 | 5 | public static void main(String[] args) { 6 | System.out.println(solution(new String[][] {{"yellowhat", "headgear"}, {"bluesunglasses", "eyewear"}, {"green_turban", "headgear"}})); 7 | } 8 | 9 | public static int solution(String[][] clothes) { 10 | int answer = 1; 11 | HashMap category = new HashMap<>(); 12 | for (String[] cloth : clothes) { 13 | // 해당 종류가 처음일 때 14 | if (category.get(cloth[1]) == null) category.put(cloth[1], 1); 15 | // 해당 종류가 이미 존재할 때 16 | else category.put(cloth[1], category.get(cloth[1]) + 1); 17 | } 18 | 19 | // 서로 다른 옷의 조합의 수 구하기 20 | for (Integer cnt : category.values()) { 21 | answer *= cnt + 1; 22 | } 23 | 24 | // 아예 안입는 경우 제외 25 | return answer - 1; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42578.위장/oh.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | 4 | public class oh { 5 | public static void main(String[] args) { 6 | int result = solution(new String[][]{{"yellowhat", "headgear"},{"bluesunglasses", "eyewear"},{"green_turban", "headgear"}}); 7 | System.out.println(result); 8 | } 9 | public static int solution(String[][] clothes) { 10 | int answer = 1; 11 | Map map = new HashMap<>(); 12 | for (int i = 0; i < clothes.length; i++) { 13 | map.put(clothes[i][1],map.getOrDefault(clothes[i][1],0)+1); 14 | } 15 | 16 | for(String keys: map.keySet()) { 17 | answer *= (map.get(keys) + 1); 18 | } 19 | 20 | answer -= 1; 21 | 22 | return answer; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42578.위장/readme.md: -------------------------------------------------------------------------------- 1 | [프로그래머스 - 42578.위장](https://programmers.co.kr/learn/courses/30/lessons/42578) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/해시/42579. 베스트앨범/README.md: -------------------------------------------------------------------------------- 1 | [프로그래머스 - 42579. 베스트앨범](https://programmers.co.kr/learn/courses/30/lessons/42579) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/힙(heap)/readme.md: -------------------------------------------------------------------------------- 1 | [프로그래머스 - 더 맵게](https://programmers.co.kr/learn/courses/30/lessons/42626) 2 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/힙(heap)/더 맵게/ch_42626.java: -------------------------------------------------------------------------------- 1 | import java.util.PriorityQueue; 2 | 3 | public class ch_42626 { 4 | public static void main(String[] args) { 5 | System.out.println(solution(new int[]{1, 2, 3, 9, 10, 12}, 7)); 6 | } 7 | 8 | private static int solution(int[] scoville, int K) { 9 | int answer = 0; 10 | PriorityQueue pq = new PriorityQueue<>(); 11 | for(int i = 0; i < scoville.length; i++){ 12 | pq.offer(scoville[i]); 13 | } 14 | 15 | for (int i = 0; i < pq.size(); i++) { 16 | if (pq.size() == 1) return -1; 17 | if (pq.peek() >= K) break; 18 | int temp = pq.poll(); 19 | int temp2 = pq.poll(); 20 | pq.offer(temp + (temp2 * 2)); 21 | answer++; 22 | } 23 | return answer; 24 | } 25 | } -------------------------------------------------------------------------------- /programmers/코딩테스트연습/힙(heap)/더 맵게/mj.java: -------------------------------------------------------------------------------- 1 | import java.util.PriorityQueue; 2 | 3 | public class D8_더맵게 { 4 | 5 | public static void main(String[] args) { 6 | int[] scoville = {1, 2, 3, 9, 10, 12}; 7 | int K = 7; 8 | int solution = solution(scoville, K); 9 | System.out.println(solution); 10 | } 11 | 12 | static public int solution(int[] scoville, int K) { 13 | int answer = 0; 14 | PriorityQueue pq= new PriorityQueue<>(); 15 | for (int i : scoville) { 16 | pq.offer(i); 17 | } 18 | 19 | // K == 0 return 0 20 | // b == 0 return -1 21 | 22 | while(pq.size() >= 2 && pq.peek() < K){ 23 | int a = pq.poll(); 24 | int b = pq.poll(); 25 | int k = a+b*2; 26 | if(k == 0) { 27 | // 계속 0이 나올 경우 28 | answer = -1; 29 | break; 30 | } 31 | pq.offer(k); 32 | answer++; 33 | } 34 | 35 | // 하나 밖에 남지 않으면 계속 진행이 어렵다. 36 | if (pq.size() == 1){ 37 | int a = pq.poll(); 38 | if(a < K) answer = -1; 39 | } 40 | 41 | return answer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /programmers/코딩테스트연습/힙(heap)/더 맵게/oh.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public static int solution(int[] scoville, int K) { 5 | int count =0; 6 | PriorityQueue que = new PriorityQueue(); 7 | for (int i : scoville) { 8 | que.add((i)); 9 | } 10 | while(true){ 11 | boolean flag = true; 12 | 13 | if(que.peek()>=K){ 14 | break; 15 | } 16 | if(que.size()==1){ 17 | count =-1; 18 | break; 19 | } 20 | int frist = que.poll(); 21 | int second = que.poll(); 22 | que.add(frist+second*2); 23 | count++; 24 | } 25 | return count; 26 | } 27 | } 28 | --------------------------------------------------------------------------------