├── archive ├── GyuMin │ ├── readme.md │ ├── 카펫.cpp │ ├── 문자열 내 맘대로.cpp │ ├── 124.cpp │ ├── 꼴등.cpp │ ├── 전화번호.cpp │ ├── 땅따먹기.cpp │ ├── 가장 큰 정사각형.cpp │ ├── 더 맵게.cpp │ ├── 멀쩡한사각형.cpp │ └── 위장.cpp ├── MoonSeong │ ├── readme.md │ ├── FindPrimeNumber.java │ ├── ShortestPathProgram.java │ ├── 210703matches.cpp │ ├── 210627Immigration.cpp │ ├── 210321rightBrackets.cpp │ ├── carpet.java │ ├── 210606jumpNTeleport(F).cpp │ ├── 210425matMult(compileError).py │ ├── a.cpp │ ├── 210418DFS.py │ ├── b.cpp │ ├── 210301baseN_game.cpp │ ├── prefix.cpp │ ├── 210321binaryTranslation.cpp │ ├── scoville(timeout).cpp │ ├── primeNum2.java │ ├── 210424findSquare(timeOut).py │ └── blackjack.cpp ├── YoungSeo │ ├── Readme.md │ ├── 멀쩡한 사각형.cpp │ ├── 124num.cpp │ ├── cloth.cpp │ ├── 문자열내맘대로정렬.cpp │ ├── 비밀지도.cpp │ ├── 완주못한선수.cpp │ ├── 땅따먹기.cpp │ ├── 더맵게.cpp │ ├── 소수만들기.cpp │ ├── 카펫.cpp │ ├── 가장 큰 정사각형.cpp │ ├── N진수게임.cpp │ ├── 오픈채팅방.cpp │ ├── 수포자.cpp │ └── 스킬트리.cpp ├── Kimsh │ ├── kimsh_first │ ├── 알고리즘 8장 코드 공부.pdf │ ├── mailProgramming_0816.cpp │ ├── mailprogramming_0224.cpp │ ├── mailprogramming_0309.cpp │ ├── mailprogramming_0316.cpp │ ├── mailprogramming_0427.cpp │ ├── mailprogramming_0510.cpp │ ├── mailprogramming_0518.cpp │ ├── 코딩테스트_1 │ ├── 코딩테스트_2 │ ├── mailprogramming_0712.cpp │ ├── 보글게임 예제 │ ├── mailproramming_0605.cpp │ └── mailprogramming_0202 ├── SongChiHoon │ ├── Baekjoon │ │ ├── monkeygame.py │ │ ├── heykakao.py │ │ ├── SMUPC │ │ │ ├── smupc.py │ │ │ ├── snowballing.py │ │ │ └── neednewfriend.py │ │ ├── LIS.py │ │ ├── blackjack.py │ │ └── weightloss.py │ ├── .vscode │ │ └── settings.json │ ├── Daily_Programming │ │ ├── Powershellcommandslist.txt │ │ ├── DP200706.cpp │ │ ├── DP200824.cpp │ │ ├── 2020_firsthalf │ │ │ ├── DP200504.cpp │ │ │ ├── DP200202.cpp │ │ │ ├── DP200315.cpp │ │ │ ├── DP200427_another.cpp │ │ │ └── DP200113.cpp │ │ ├── DP200817.cpp │ │ └── DP200831.cpp │ ├── Programmers │ │ ├── stringsort.py │ │ ├── jumpandteleport.py │ │ ├── weeklychallenge │ │ │ ├── voweldictionary.py │ │ │ └── lackmoneycount.py │ │ ├── Kakao │ │ │ ├── menurenewal.cpp │ │ │ ├── friends4block.cpp │ │ │ ├── secretmap.cpp │ │ │ ├── CraneKakao.cpp │ │ │ └── ndigitgame.cpp │ │ ├── greedy │ │ │ └── joystick.cpp │ │ ├── groundpicking.cpp │ │ ├── Immigration.py │ │ ├── 2diffbits.py │ │ ├── WatermelonSugarHigh.cpp │ │ ├── inandout.py │ │ ├── IntegerTriagle.cpp │ │ ├── bruteforce │ │ │ └── BP-Carpet.cpp │ │ ├── binarychange.py │ │ ├── biggestsquare.cpp │ │ ├── samsungexplain │ │ │ └── easy2048.md │ │ ├── stringsort.cpp │ │ ├── Hash │ │ │ ├── Hash-undercover.cpp │ │ │ ├── Hash-unfinishedrunner.cpp │ │ │ └── Hash-phonecalllist.cpp │ │ ├── matrixmultiply.py │ │ ├── Sorting-findingK.java │ │ ├── rightbracket.py │ │ ├── dynamicprogramming │ │ │ └── Longjump.cpp │ │ ├── CaesarCode.cpp │ │ ├── scoville.cpp │ │ ├── 124countries.cpp │ │ ├── rotatebracket.py │ │ └── Pipemoving.cpp │ └── OnBook │ │ ├── FindingK.cpp │ │ ├── Numbergame.cpp │ │ ├── knapsackproblem.cpp │ │ ├── PICNIC.cpp │ │ ├── OCR.cpp │ │ └── LIS.cpp ├── ayt │ ├── test.cpp │ ├── text2.cpp │ ├── 프로그래머스_점프와순간이동.cpp │ ├── 매프200308.cpp │ ├── 프로그래머스_부족한금액계산하기.cpp │ ├── 프로그래머스_수박수박.cpp │ ├── 프로그래머스_문자열내마음대로정렬.cpp │ ├── 프로그래머스_H-Index.cpp │ ├── 매프191223.cpp │ ├── 매프200511.cpp │ ├── 매프200706.cpp │ ├── 매프200817.cpp │ ├── 프로그래머스_예상대진표.cpp │ ├── 프로그래머스_멀쩡한사각형.cpp │ ├── 백준_ SMUPC의등장.cpp │ ├── 프로그래머스_멀리뛰기.cpp │ ├── 매프200315.cpp │ ├── 매프200209.cpp │ ├── 프로그래머스_카펫.cpp │ ├── 프로그래머스_시저암호.cpp │ ├── 프로그래머스_완주하지못한선수_hashset.cpp │ ├── 프로그래머스_비밀지도.cpp │ ├── 프로그래머스_완주하지못한선수.cpp │ ├── 매프200608.cpp │ ├── 매프200810.cpp │ ├── 프로그래머스_구명보트.cpp │ ├── 프로그래머스_가장큰정사각형찾기.cpp │ ├── 매프200608_practice.cpp │ ├── 프로그래머스_주식가격.cpp │ ├── 매프200127.cpp │ ├── 매프200106.cpp │ ├── 매프200427.cpp │ ├── 프로그래머스_전화번호목록.cpp │ ├── 백준_헤이카카오.cpp │ ├── 프로그래머스_124나라의숫자.cpp │ ├── 프로그래머스_올바른괄호.cpp │ ├── 매프200831.cpp │ ├── 매프200518.cpp │ ├── 프로그래머스_입국심사.cpp │ ├── 매프200504.cpp │ ├── 매프200120.cpp │ ├── 백준_연속합.cpp │ ├── 매프200622.cpp │ ├── 백준_눈덩이굴리기.cpp │ ├── 프로그래머스_행렬의곱샘.cpp │ ├── 프로그래머스_영어끝말잇기.cpp │ ├── 프로그래머스_정수삼각형.cpp │ ├── 백준_창영이와버스.cpp │ ├── 쿼드트리뒤집기.cpp │ ├── 매프191208.cpp │ ├── 매프200202.cpp │ ├── 백준_근손실.cpp │ ├── 매프191208-2.cpp │ ├── 매프191110.cpp │ ├── 백준_창영이와점프.cpp │ ├── 프로그래머스_N-Queen.cpp │ ├── 프로그래머스_모의고사.cpp │ ├── 프로그래머스_튜플.cpp │ ├── 프로그래머스_스킬트리.cpp │ ├── 매프200824.cpp │ └── 프로그래머스_실패율.cpp ├── Simple matter │ ├── 20.07.27 matter │ ├── 20.08.17 matter │ ├── 20.08.03 matter │ ├── 20.07.13 matter │ ├── 20.08.31 matter │ ├── 20.04.13 matter │ ├── 20.05.25 matter │ ├── 20.08.24 matter │ ├── 20.01.26 matter │ ├── 20.05.04 matter │ ├── 20.07.20 matter │ ├── 19.12.08 matter │ ├── 20.02.02 matter │ ├── 20.06.08 matter │ ├── 20.07.06 matter │ ├── 19.11.10 matter │ ├── 20.01.13 matter │ ├── 20.01.20 matter │ ├── 20.05.18 matter │ ├── 20.04.20 matter │ ├── 20.06.01 matter │ ├── 20.03.08 matter │ ├── 20.03.29 matter │ ├── 20.06.29 matter │ ├── 20.02.09 matter │ ├── 19.12.23 matter │ ├── 20.01.06 matter │ ├── 20.05.11 matter │ ├── 20.06.22 matter │ ├── 19.12.16 matter │ ├── 20.03.15 matter │ ├── 20.06.15 matter │ ├── 20.02.23 matter │ ├── 20.08.10 matter │ ├── 19.12.30 matter │ ├── 20.09.07 matter │ ├── 20.03.22 matter │ ├── 20.04.27 matter │ └── 20.04.05 matter ├── SeHyeon │ ├── 20.08.31 matter.cpp │ ├── 20.10.07 Coding Practice No.14.cpp │ ├── 20.08.31 matter(other Ver).cpp │ ├── 21.06.06 Coding Practice No.58.cpp(Complete) │ ├── 20.08.17 matter.cpp │ ├── 20.11.25 Coding Practice No.22.cpp │ ├── 21.07.25 Coding Practice No.68.py │ ├── 20.11.11 Coding Practice No.20.cpp │ ├── 21.07.18 Coding Practice No.67.py │ ├── 20.12.02 Coding Practice No.23.cpp │ ├── 21.09.12 Coding Practice No.80.cpp │ ├── 21.07.11 Coding Practice No.66.py │ ├── 9-6 Morse Code(Full Search).cpp │ ├── 20.03.08 matter.cpp │ ├── 20.12.20 Coding Practice No.25.cpp │ ├── 21.03.21 Coding Practice No.49.cpp │ ├── 21.02.07 Coding Practice No.39.cpp │ ├── 19.12.16 matter(Simple.ver).cpp │ ├── 9-7 Morse Code 9-7(Full Serach Ver2).cpp │ ├── 20.07.06 matter.cpp │ ├── 9-21 numberGame.cpp │ ├── 21.07.25 Coding Practice No.69.py │ ├── 19.12.08 matter.cpp │ ├── 20.02.23 matter.cpp │ ├── 21.01.17 Coding Practice No.33.cpp │ ├── 21.09.05 Coding Practice No.79.cpp │ ├── 9-15 shortestPath2.cpp │ ├── 20.04.27 matter.cpp │ ├── 20.10.14 Coding Practice No.15.cpp │ ├── 20.02.09 matter.cpp │ ├── 20.02.02 matter.cpp │ ├── 20.09.07 Coding Practice No.11(Success).cpp │ ├── 20.05.11 Coding Practice No.2.cpp │ ├── 21.01.09 Coding Practice No.32.cpp │ ├── 19.12.23 matter.cpp │ ├── 20.06.22 matter.cpp │ ├── 20.09.07 Coding Practice No.11(Not Success).cpp │ ├── 9-16 waveBarJim(Full Search).cpp │ ├── 20.06.08 matter.cpp │ ├── 21.06.27 Coding Practice No.62.cpp │ ├── 20.01.26 matter.cpp │ ├── 9-1 lis4.cpp │ ├── 20.05.11 matter.cpp │ ├── 20.01.20 matter (my method).cpp │ ├── 21.05.30 Coding Practice No.57.cpp(Brute Force - Time out) │ ├── 20.12.27 Coding Practice No.27(Compelete).cpp │ ├── 20.05.18 matter.cpp │ ├── 21.07.03 Coding Practice No.63.cpp │ ├── 19.12.30 matter.cpp │ ├── extra study bound │ ├── 21.01.02 Coding Practice No.29.cpp │ ├── 21.07.11 Coding Practice No.65(Compelete).cpp │ ├── 8-1 jumpGame.cpp │ ├── 19.12.16 matter.cpp │ ├── 20.08.10 Coding Practice No.8.cpp │ ├── 21.04.25 Coding Practice No.53.cpp │ ├── 9-4 recognize.cpp │ ├── 20.01.13 matter.cpp │ ├── 21.04.18 Coding Practice No.52.cpp │ ├── 20.05.18 Coding Practice No.3.cpp │ ├── 9-10 KLis.cpp │ ├── 9-11 reconstruct(Morse Code).cpp │ ├── 19.11.10 matter Ver init.cpp │ ├── 21.06.06 Coding Practice No.58(Time out - DP).cpp │ ├── 9-9 Morse Code(kth).cpp │ ├── 20.10.30 Coding Practice No.18.cpp │ ├── 21.09.12 Coding Practice No.81.cpp │ ├── 21.02.14 Coding Practice No.41.cpp │ ├── 20.12.27 Coding Practice No.28(Compelete).cpp │ ├── 20.09.07 Coding Practice No.11(Not Success Ver2).cpp │ ├── 20.06.15 matter.cpp │ └── 9-17 waveBarJim(DP).cpp └── Coding Practice │ ├── No2.txt │ ├── No3.txt │ ├── No10.txt │ ├── No23.txt │ ├── No26.txt │ ├── No53.txt │ ├── No12.txt │ ├── No55.txt │ ├── No14.txt │ ├── No15.txt │ ├── No8.txt │ ├── No67.txt(BAEKJOON) │ ├── No49.txt │ ├── No7.txt │ ├── No20.txt │ ├── No68.txt(BAEKJOON) │ ├── No22.txt │ ├── No66.txt(BAEKJOON) │ ├── No27.txt │ ├── No60.txt │ ├── No28.txt │ ├── No79.txt │ ├── No52.txt │ ├── No57.txt │ ├── No13.txt │ ├── No39.txt │ ├── No11.txt │ └── No81.txt ├── README.md └── Problem └── Yutae ├── Week1 ├── B2839(설탕배달).cpp └── B1074(Z).cpp ├── B9663(N-Queen).cpp └── B1182(부분순열의합).cpp /archive/GyuMin/readme.md: -------------------------------------------------------------------------------- 1 | # 어부 -------------------------------------------------------------------------------- /archive/MoonSeong/readme.md: -------------------------------------------------------------------------------- 1 | 손문성 2 | -------------------------------------------------------------------------------- /archive/YoungSeo/Readme.md: -------------------------------------------------------------------------------- 1 | 최영서 2 | -------------------------------------------------------------------------------- /archive/Kimsh/kimsh_first: -------------------------------------------------------------------------------- 1 | This is user Kimsh's first file. 2 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/monkeygame.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if __name__ == "__main__": 4 | n -------------------------------------------------------------------------------- /archive/ayt/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | std::cout << "Hello world!"; 5 | } -------------------------------------------------------------------------------- /archive/ayt/text2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/ayt/text2.cpp -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/heykakao.py: -------------------------------------------------------------------------------- 1 | a, b, c = input.split() 2 | 3 | a = int(a) 4 | d = int(b) 5 | k = int(c) -------------------------------------------------------------------------------- /archive/Kimsh/알고리즘 8장 코드 공부.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/알고리즘 8장 코드 공부.pdf -------------------------------------------------------------------------------- /archive/SongChiHoon/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "xstring": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /archive/Simple matter/20.07.27 matter: -------------------------------------------------------------------------------- 1 | 스택(Stack)을 이용해서 큐(Queue)를 구현하시오. 2 | 3 | 4 | 5 | Implement a queue using stacks. 6 | -------------------------------------------------------------------------------- /archive/Simple matter/20.08.17 matter: -------------------------------------------------------------------------------- 1 | 주어진 정수가 4의 거듭제곱인지 확인하시오. 2 | 3 | 4 | 5 | Given an integer, check if it is a power of 4. 6 | -------------------------------------------------------------------------------- /archive/Kimsh/mailProgramming_0816.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailProgramming_0816.cpp -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0224.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailprogramming_0224.cpp -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0309.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailprogramming_0309.cpp -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0316.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailprogramming_0316.cpp -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0427.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailprogramming_0427.cpp -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0510.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailprogramming_0510.cpp -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0518.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/Kimsh/mailprogramming_0518.cpp -------------------------------------------------------------------------------- /archive/MoonSeong/FindPrimeNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/MoonSeong/FindPrimeNumber.java -------------------------------------------------------------------------------- /archive/MoonSeong/ShortestPathProgram.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/MoonSeong/ShortestPathProgram.java -------------------------------------------------------------------------------- /archive/Simple matter/20.08.03 matter: -------------------------------------------------------------------------------- 1 | 퀵정렬(quick sort)와 합병정렬(merge sort)이 차이점을 서술 하시오. 2 | 3 | 4 | 5 | Describe differences between quick sort and merge sort. 6 | -------------------------------------------------------------------------------- /archive/Simple matter/20.07.13 matter: -------------------------------------------------------------------------------- 1 | 백만개의 정수가 들어있는 배열을 가장 빨리 정렬하시오. 모든 정수는 1조보다 작습니다. 2 | 3 | 4 | 5 | 힌트) 퀵소트 아님. 6 | 7 | 8 | 9 | Sort an array with million integers. 10 | -------------------------------------------------------------------------------- /archive/Simple matter/20.08.31 matter: -------------------------------------------------------------------------------- 1 | 1~N 까지 있는 정수 배열에 원소 하나가 없어졌습니다. 없어진 원소의 값을 구하시오. 2 | 3 | 4 | 5 | Given an integer array of 1~N except one number, find the missing integer. 6 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/Powershellcommandslist.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HumanHyeon/Algorithm_Book/HEAD/archive/SongChiHoon/Daily_Programming/Powershellcommandslist.txt -------------------------------------------------------------------------------- /archive/Simple matter/20.04.13 matter: -------------------------------------------------------------------------------- 1 | 이진 트리를 루트 노드를 기준으로 좌우반전 하시오. 2 | 3 | 이 문제는 구글이 Homebrew 창시자에게 낸 문제로 유명합니다. 4 | 5 | 6 | 7 | Given a binary tree root node, reverse the tree horizontally. 8 | -------------------------------------------------------------------------------- /archive/Simple matter/20.05.25 matter: -------------------------------------------------------------------------------- 1 | 단방향 연결 리스트(Singly linked list)가 주어지면 O(n log n) 시간복잡도로 정렬하시오. 2 | 3 | 4 | 5 | Given a singly linked list, sort the list in O(n log n) time complexity. 6 | -------------------------------------------------------------------------------- /archive/Simple matter/20.08.24 matter: -------------------------------------------------------------------------------- 1 | 이진탐색트리안에 X보다 크고 Y보다 작은 모든 노드 값을 프린트 하시오. 2 | 3 | 4 | 5 | Given a binary search tree, print all node values that are bigger than X and smaller than Y. 6 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/stringsort.py: -------------------------------------------------------------------------------- 1 | def strange_sort(strings, n): 2 | return sorted(sorted(strings), key=lambda x: x[n]) 3 | 4 | strings = ["sun", "bed", "car"] 5 | print(strange_sort(strings, 1)) -------------------------------------------------------------------------------- /archive/Simple matter/20.01.26 matter: -------------------------------------------------------------------------------- 1 | 주어진 string 에 모든 단어를 거꾸로 하시오. 2 | 3 | Reverse all the words in the given string. 4 | 5 | 6 | 7 | 예제) 8 | 9 | Input: “abc 123 apple” 10 | 11 | Output: “cba 321 elppa” 12 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_점프와순간이동.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | 3 | int solution(int n){ 4 | int ans = 0; 5 | 6 | while(n>0){ 7 | if(n%2) ans++; 8 | n/= 2; 9 | } 10 | 11 | return ans; 12 | } 13 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.08.31 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int missingN(int input[], int n) { 5 | int i; 6 | for (int i = 0; i < n; i++) 7 | if (input[i] != i + 1) return i + 1; 8 | return -1; 9 | } 10 | -------------------------------------------------------------------------------- /archive/Coding Practice/No2.txt: -------------------------------------------------------------------------------- 1 | 문제 설명 2 | 길이가 n이고, 수박수박수박수....와 같은 패턴을 유지하는 문자열을 리턴하는 함수, solution을 완성하세요. 예를들어 n이 4이면 수박수박을 리턴하고 3이라면 수박수를 리턴하면 됩니다. 3 | 4 | 제한 조건 5 | n은 길이 10,000이하인 자연수입니다. 6 | 입출력 예 7 | n return 8 | 3 수박수 9 | 4 수박수박 10 | -------------------------------------------------------------------------------- /archive/Simple matter/20.05.04 matter: -------------------------------------------------------------------------------- 1 | O(n log n)시간 복잡도를 가진 정수 배열 정렬 알고리즘을 구현하시오. 2 | 3 | 4 | 5 | Implement an O(n log n) time complexity sorting algorithm. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: [3, 1, 5, 6] 12 | 13 | Output: [1, 3, 5, 6] 14 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/jumpandteleport.py: -------------------------------------------------------------------------------- 1 | def solution(n): 2 | count = 0 3 | while n > 0: 4 | quotient, remainder = divmod(n, 2) 5 | n = quotient 6 | if remainder != 0: 7 | count += 1 8 | return count 9 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/weeklychallenge/voweldictionary.py: -------------------------------------------------------------------------------- 1 | def solution(word): 2 | ret = 0 3 | num = [781, 156, 31, 6, 1] 4 | 5 | for i in range(len(word)): 6 | ret += "AEIOU".find(word[i]) * num[i] + 1 7 | 8 | return ret -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/SMUPC/smupc.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | S = stdin.readline().rstrip() 4 | 5 | for char in S: 6 | char_ascii = ord(char) 7 | position_sum = sum(map(int, list(str(char_ascii)))) 8 | 9 | print(char * position_sum) 10 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.10.07 Coding Practice No.14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | std::vector solution(int brown, int yellow) { 3 | for (int i = 1; i * i <= yellow; i++) if (!(yellow % i) && !(brown - (yellow / i + 2) * 2 - i * 2)) return { yellow / i + 2, i + 2 }; 4 | } 5 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Kakao/menurenewal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(vector orders, vector course) { 7 | vector answer; 8 | 9 | return answer; 10 | } -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/LIS.py: -------------------------------------------------------------------------------- 1 | N = int(input()) 2 | 3 | A = list(map(int, input().split())) 4 | 5 | dp = [1] * N 6 | 7 | for i in range(N): 8 | for j in range(i): 9 | if A[j] < A[i]: 10 | dp[i] = max(dp[i],dp[j]+1) 11 | 12 | print(max(dp)) 13 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.08.31 matter(other Ver).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int missingN(int input[], int n) { 5 | int answer = (n + 1) * (n + 2) / 2; //1개 빠진 개수이니 n + 1 6 | for (int i = 0; i < n; i++) 7 | answer -= input[i]; 8 | return answer; 9 | } 10 | -------------------------------------------------------------------------------- /archive/Simple matter/20.07.20 matter: -------------------------------------------------------------------------------- 1 | 이진 트리가 주어지면 루트 노드부터 레벨별로 프린트 하시오. 프린트 방식은 홀수 레벨은 왼쪽에서 오른쪽으로, 짝수 레벨은 오른쪽에서 왼쪽으로 프린트 하시오. 루트노드는 레벨 1입니다. 예제를 보시오. 2 | 3 | 4 | 5 | 1 6 | 7 | / \ 8 | 9 | 2 3 10 | 11 | / \ / \ 12 | 13 | 4 5 6 7 14 | 15 | 16 | 17 | 프린트: 1, 3, 2, 4, 5, 6, 7. 18 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/greedy/joystick.cpp: -------------------------------------------------------------------------------- 1 | // https://programmers.co.kr/learn/courses/30/lessons/42860?language=cpp 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(string name) { 9 | int answer = 0; 10 | return answer; 11 | } -------------------------------------------------------------------------------- /archive/Simple matter/19.12.08 matter: -------------------------------------------------------------------------------- 1 | 2 | 정수로된 배열이 주어지면, 각 원소가 자신을 뺀 나머지 원소들의 곱셈이 되게하라. 3 | 단, 나누기 사용 금지, O(n) 시간복잡도 4 | 5 | Given an integer array, make each element a product of all element values without itself. 6 | 7 | 예제) 8 | input: [1, 2, 3, 4, 5] 9 | output: [120, 60, 40, 30, 24] 10 | -------------------------------------------------------------------------------- /archive/MoonSeong/210703matches.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int solution(int n, int a, int b) 6 | { 7 | if ((a % 2 == 1 && a+1 == b) || (b % 2 == 1 && b+1 == a)) 8 | return 1; 9 | else 10 | return 1 + solution(n/2, (a+(a%2))/2, (b+(b%2))/2); 11 | } 12 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.06.06 Coding Practice No.58.cpp(Complete): -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12980 2 | 3 | int solution(int n) { 4 | int ans = 0; 5 | 6 | while (n > 0) { 7 | if (n % 2) 8 | ans++; 9 | n /= 2; 10 | } 11 | return (ans); 12 | } 13 | -------------------------------------------------------------------------------- /archive/Simple matter/20.02.02 matter: -------------------------------------------------------------------------------- 1 | 정수 배열(int array)이 주어지면 두번째로 큰 값을 프린트하시오. 2 | 3 | 4 | 5 | Given an integer array, find the second largest element. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: [10, 5, 4, 3, -1] 12 | 13 | Output: 5 14 | 15 | 16 | 17 | Input: [3, 3, 3] 18 | 19 | Output: Does not exist. 20 | -------------------------------------------------------------------------------- /archive/SongChiHoon/OnBook/FindingK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void generate(int n, int m, string s) { 5 | if(n == 0 && m == 0) { 6 | cout << s << endl; 7 | return; 8 | } 9 | if(n > 0) generate(n-1, m, s + "-"); 10 | if(m > 0) generate(n, m-1, s + "o"); 11 | } -------------------------------------------------------------------------------- /archive/SeHyeon/20.08.17 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int power(int num) { 4 | if (num == 4) return 1; 5 | else if (!(num / 4)) return -1; 6 | return power(num / 4); 7 | } 8 | 9 | int main() { 10 | int input; std::cin >> input; 11 | std::cout << (power(input) == 1 ? "TRUE" : "FALSE") << std::endl; 12 | } 13 | -------------------------------------------------------------------------------- /archive/ayt/매프200308.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int input[] = { -1,3,-1,5,4 }; 8 | int N = 2; 9 | 10 | sort(input, input + sizeof(input) / sizeof(*input)); 11 | cout << input[sizeof(input) / sizeof(*input) - N]; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /archive/Simple matter/20.06.08 matter: -------------------------------------------------------------------------------- 1 | 정수 배열이 주어지면 , 배열 안의 모든 정수의 최대 공약수(GCD)를 구하시오. 2 | 3 | 시간 복잡도 제한 O(n) 4 | 5 | 6 | 7 | Given an integer array, find the greatest common denominator of all elements. 8 | 9 | 10 | 11 | input: [3, 2, 1] 12 | 13 | output: 1 14 | 15 | 16 | 17 | input: [2, 4, 6, 8] 18 | 19 | output: 2 20 | -------------------------------------------------------------------------------- /archive/Simple matter/20.07.06 matter: -------------------------------------------------------------------------------- 1 | 주어진 정수를 2진법으로 나타내었을때 1의 갯수를 리턴하시오. 2 | 3 | 4 | 5 | Given an integer, count number of 1s in binary representation of an integer. 6 | 7 | 8 | 9 | 시간 복잡도: O(log n) 10 | 11 | 12 | 13 | input: 6 // 110 14 | 15 | output: 2 16 | 17 | 18 | 19 | input: 13 // 1101 20 | 21 | output: 3 22 | -------------------------------------------------------------------------------- /archive/Kimsh/코딩테스트_1: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(int n) { 7 | string answer = ""; 8 | int i = 0; 9 | while(i 2 | #include 3 | bool solution(std::vector phone_book) { 4 | for (auto fetch : phone_book) 5 | for (auto cmpStr : phone_book) 6 | if (fetch == cmpStr) continue; 7 | else if (fetch.find(cmpStr) == 0) return false; 8 | return true; 9 | } 10 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.07.25 Coding Practice No.68.py: -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/21734 2 | 3 | inputStr = input() 4 | 5 | for i in range(len(inputStr)): 6 | asci = str(ord(inputStr[i])) 7 | cycle = 0 8 | outputstr = "" 9 | for j in asci: 10 | cycle = cycle + int(j) 11 | outputStr = inputStr[i] * cycle 12 | print(outputStr) 13 | -------------------------------------------------------------------------------- /archive/Simple matter/20.01.13 matter: -------------------------------------------------------------------------------- 1 | 정수 배열과 타겟 숫자가 주어지면, 합이 타겟값이 되는 두 원소의 인덱스를 찾으시오. 2 | 3 | 단, 시간복잡도 O(n) 여야 합니다. 4 | 5 | 6 | 7 | Given an array of integers and a target integer, find two indexes of the array element that sums to the target number. 8 | 9 | 10 | 11 | 예제) 12 | 13 | Input: [2, 5, 6, 1, 10], 타겟 8 14 | 15 | Output: [0, 2] // 배열[0] + 배열[2] = 8 16 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_수박수박.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(int n) { 7 | string answer = ""; 8 | 9 | for(int i = 0;i < n; i++) { 10 | if(i%2==0) 11 | answer.append("수"); 12 | else 13 | answer.append("박"); 14 | } 15 | 16 | return answer; 17 | } 18 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/weeklychallenge/lackmoneycount.py: -------------------------------------------------------------------------------- 1 | def solution(price, money, count): 2 | answer = -1 3 | end_price = 0 4 | 5 | for a in range(count) : 6 | end_price += price * (a+1) 7 | 8 | if(end_price > money) : 9 | answer = end_price - money 10 | 11 | else : 12 | answer = 0 13 | 14 | return answer -------------------------------------------------------------------------------- /archive/Simple matter/20.01.20 matter: -------------------------------------------------------------------------------- 1 | 간격(interval)로 이루어진 배열이 주어지면, 겹치는 간격 원소들을 합친 새로운 배열을 만드시오. 간격은 시작과 끝으로 이루어져 있으며 시작은 끝보다 작거나 같습니다. 2 | 3 | 4 | 5 | Given a list of intervals, merge intersecting intervals. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: {{2,4}, {1,5}, {7,9}} 12 | 13 | Output: {{1,5}, {7,9}} 14 | 15 | 16 | 17 | Input: {{3,6}, {1,3}, {2,4}} 18 | 19 | Output: {{1,6}} 20 | -------------------------------------------------------------------------------- /archive/MoonSeong/210627Immigration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | table[] : 각 심사대의 남은시간 3 | 4 | time = [7, 10] 5 | 6 | [time]: [ ] 7 | 0: 7 10 8 | 7: 7 3 9 | 10: 4 10 10 | 14: 7 6 11 | 20: 1 10 or 20: 1 0 12 | 21: 0 9 or 21: 7 -1 13 | 28: -7 2 or 28: 0 -8 14 | 30: -9 0 15 | 16 | 17 | 최적이 아닌경우: 18 | 모든 심사가 끝났을 때 (모든 심사대(table)가 0이하), 19 | 20 | 각각 심사시간(time[i]) < 심사대가 빈시간(abs(table[i])) 인 경우 21 | */ 22 | -------------------------------------------------------------------------------- /archive/Simple matter/20.05.18 matter: -------------------------------------------------------------------------------- 1 | 정수 배열과 정수 k가 주어지면 모든 원소를 k칸씩 앞으로 옮기시오. 2 | 3 | 4 | 5 | Given an array and an integer K, shift all elements in the array K times. 6 | 7 | 8 | 9 | input: [1, 2, 3, 4, 5], k = 2 10 | 11 | output: [3, 4, 5, 1, 2] 12 | 13 | 14 | 15 | input: [0, 1, 2, 3, 4], k = 1 16 | 17 | output: [1, 2, 3, 4, 0] 18 | 19 | 20 | 21 | 시간복잡도와 공간복잡도를 최대한 최적화 하시오. 22 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/groundpicking.cpp: -------------------------------------------------------------------------------- 1 | // https://programmers.co.kr/learn/courses/30/lessons/12913?language=cpp 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int solution(vector > land) 8 | { 9 | int answer = 0; 10 | 11 | // [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. 12 | cout << "Hello Cpp" << endl; 13 | 14 | return answer; 15 | } -------------------------------------------------------------------------------- /archive/SeHyeon/20.11.11 Coding Practice No.20.cpp: -------------------------------------------------------------------------------- 1 | long long gcd(int w, int h) { 2 | if (w > h) { 3 | int tmp = w; 4 | w = h; 5 | h = tmp; 6 | } 7 | while (w != 0) { 8 | int n = h % w; 9 | h = w; 10 | w = n; 11 | } 12 | return h; 13 | } 14 | 15 | long long solution(int w, int h) { 16 | long long g = gcd(w, h); 17 | return (long long)w * h - g * ((w / g) + (h / g) - 1); 18 | } 19 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.07.18 Coding Practice No.67.py: -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/11053 2 | 3 | n = int(input()) 4 | nl = list(map(int, input().split())) 5 | 6 | dp = [1 for _ in range(n)] 7 | for i in range(1, n): 8 | std = nl[i] 9 | for j in range(i): 10 | cmp = nl[j] 11 | if std > cmp: 12 | dp[i] = max(dp[i], dp[j] + 1) 13 | 14 | print(max(dp)) 15 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/blackjack.py: -------------------------------------------------------------------------------- 1 | N, M = map(int, input().split()) 2 | arr = list(map(int, input().split())) 3 | result = 0 4 | for i in range(N): 5 | for j in range(i+1, N): 6 | for k in range(j+1, N): 7 | if arr[i] + arr[j] + arr[k] > M: 8 | continue 9 | else: 10 | result = max(result, arr[i]+arr[j]+arr[k]) 11 | print(result) 12 | -------------------------------------------------------------------------------- /archive/Coding Practice/No3.txt: -------------------------------------------------------------------------------- 1 | 어떤 문장의 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꾸는 암호화 방식을 시저 암호라고 합니다. 예를 들어 AB는 1만큼 밀면 BC가 되고, 3만큼 밀면 DE가 됩니다. z는 1만큼 밀면 a가 됩니다. 문자열 s와 거리 n을 입력받아 s를 n만큼 민 암호문을 만드는 함수, solution을 완성해 보세요. 2 | 3 | 제한 조건 4 | 공백은 아무리 밀어도 공백입니다. 5 | s는 알파벳 소문자, 대문자, 공백으로만 이루어져 있습니다. 6 | s의 길이는 8000이하입니다. 7 | n은 1 이상, 25이하인 자연수입니다. 8 | 입출력 예 9 | s n result 10 | AB 1 BC 11 | z 1 a 12 | a B z 4 e F d 13 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.12.02 Coding Practice No.23.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define PNT(N) ((N) == 1 || (N) == 2 ? (N) : 4) 3 | using namespace std; 4 | 5 | string solution(int n) { 6 | string answer = ""; 7 | int div = n, mod; 8 | while(div != 0) { 9 | mod = div % 3; 10 | div = div / 3; 11 | if (!mod) div--; 12 | answer = to_string(PNT(mod)) + answer; 13 | } 14 | return answer; 15 | } 16 | -------------------------------------------------------------------------------- /archive/Simple matter/20.04.20 matter: -------------------------------------------------------------------------------- 1 | 2차 정수 배열(2D int array)가 주어지면, 소용돌이 모양으로 원소들을 프린트하시오. 예제를 보시오. 2 | 3 | 4 | 5 | Given a 2D integer array, print all elements in a circular spiral shape starting from [0][0]. See example. 6 | 7 | 8 | 9 | 예제) 10 | 11 | input: 12 | 13 | [[1, 2, 3], 14 | 15 | [8, 9, 4], 16 | 17 | [7, 6, 5]] 18 | 19 | 20 | 21 | Output: 22 | 23 | 1, 2, 3, 4, 5, 6, 7, 8, 9 24 | -------------------------------------------------------------------------------- /archive/Simple matter/20.06.01 matter: -------------------------------------------------------------------------------- 1 | 정렬된 정수 배열이 있습니다. 이 배열의 모든 원소들을 오른쪽으로 랜덤하게 Z번 이동하였습니다. 2 | 3 | 예를 들면 [1, 2, 3, 4, 5] -> [3, 4, 5, 1, 2]. 4 | 5 | 이런 배열과 정수 K 가 주어지면, 배열안에 K가 존재하는지 찾으시오. 6 | 7 | 존재한다면 배열의 인덱스, 존재하지 않다면 -1 을 리턴하시오. 8 | 9 | 시간복잡도 제한 O(log N). 10 | 11 | 12 | 13 | input: [3, 4, 5, 1, 2], 4 14 | 15 | output: 1 16 | 17 | 18 | 19 | input: [2, 4, 5, 1], 3 20 | 21 | output: -1 22 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.09.12 Coding Practice No.80.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/82612 2 | 3 | #define SUB(X, Y) ((X) > (Y) ? 0 : (Y) - (X)) 4 | 5 | long long allPrice(int p, int c) { 6 | if (!c) 7 | return 0; 8 | return (p * c + allPrice(p, c - 1)); 9 | } 10 | 11 | long long solution(int price, int money, int count) { 12 | return (SUB(money, allPrice(price, count))); 13 | } 14 | -------------------------------------------------------------------------------- /archive/Simple matter/20.03.08 matter: -------------------------------------------------------------------------------- 1 | 정수 배열(int array)과 정수 N이 주어지면, N번째로 큰 배열 원소를 찾으시오. 2 | 3 | 4 | 5 | Given an integer array and integer N, find the Nth largest element in the array. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: [-1, 3, -1, 5, 4], 2 12 | 13 | Output: 4 14 | 15 | 16 | 17 | Input: [2, 4, -2, -3, 8], 1 18 | 19 | Output: 8 20 | 21 | 22 | 23 | Input: [-5, -3, 1], 3 24 | 25 | Output: -5 26 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.07.11 Coding Practice No.66.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | nl = list(map(int, input().split())) 3 | maxSum, tmpSum = 0, 0 4 | 5 | if max(nl) < 0: 6 | maxSum = max(nl) 7 | else: 8 | for i in range(n): 9 | tmpSum = tmpSum + nl[i] 10 | if maxSum < tmpSum: 11 | maxSum = tmpSum 12 | if tmpSum < 0: 13 | tmpSum = 0 14 | print(maxSum) 15 | -------------------------------------------------------------------------------- /archive/Simple matter/20.03.29 matter: -------------------------------------------------------------------------------- 1 | 두개의 정렬된(sorted) 정수 링크드리스트(linked list)가 주어지면, 두 리스트를 합친 정렬된 링크드리스트를 만드시오. 2 | 3 | 4 | 5 | Given two sorted integer linked lists, merge the two linked lists. Merged linked list must also be sorted. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: 1->2->3, 1->2->3 12 | 13 | Output: 1->1->2->2->3->3 14 | 15 | 16 | 17 | Input: 1->3->5->6, 2->4 18 | 19 | Output: 1->2->3->4->5->6 20 | -------------------------------------------------------------------------------- /archive/YoungSeo/멀쩡한 사각형.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long long solution(int w, int h){ 5 | int x; //최대공약수 6 | long long total_square = (long long)w * (long long)h; 7 | 8 | //최대공약수 구하기 9 | for (int i = (w < h) ? w : h; i > 0; i--) { 10 | if ((w % i == 0) && (h % i == 0)) { 11 | x = i; 12 | break;} 13 | } 14 | return total_square - x * ((w / x) + (h / x) - 1); 15 | } 16 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_문자열내마음대로정렬.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int m; 8 | 9 | bool cmp(string a,string b) { 10 | return a[m] == b[m] ? a < b : a[m] < b[m]; 11 | } 12 | 13 | vector solution(vector strings, int n) { 14 | m = n; 15 | sort(strings.begin(), strings.end(), cmp); 16 | 17 | return strings; 18 | } 19 | -------------------------------------------------------------------------------- /archive/Simple matter/20.06.29 matter: -------------------------------------------------------------------------------- 1 | 반복된 알파벳으로 이루어진 문자배열이 주어지면 연속으로 중복된 알파벳이 없도록 문자배열을 재배열하여 리턴하시오. 불가능 하다면 empty string을 리턴하시오. 2 | 3 | 4 | 5 | Given a string with repeated characters, rearrange the string so that no two adjacent characters are the same. If this is impossible, return an empty string. 6 | 7 | 8 | 9 | input: "aaabbc" 10 | 11 | output: "ababac" 12 | 13 | 14 | 15 | input: "aaac" 16 | 17 | output: "" 18 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Immigration.py: -------------------------------------------------------------------------------- 1 | def impossible(n, middle, times): 2 | return sum([middle // x for x in times]) < n 3 | 4 | def solution(n, times): 5 | left, right = 1, max(times)*n 6 | while left < right: 7 | middle = (left + right) // 2 8 | if impossible(n, middle, times): 9 | left = middle + 1 10 | else: 11 | right = middle 12 | return left 13 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_H-Index.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(vector citations) { 8 | int answer = 0; 9 | 10 | sort(citations.rbegin(), citations.rend()); 11 | while(1){ 12 | if(citations[answer]<=answer||answer>citations.size()) break; 13 | ++answer; 14 | } 15 | 16 | return answer; 17 | } 18 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-6 Morse Code(Full Search).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void generate(int n, int m, string s) { 5 | if (n == 0 && m == 0) { 6 | cout << s << endl; 7 | return; 8 | } 9 | 10 | if (n > 0) generate(n - 1, m, s + "-"); 11 | if (m > 0) generate(n, m - 1, s + "o"); 12 | } 13 | 14 | int main() { 15 | string s = ""; 16 | int n, m; 17 | cin >> n >> m; 18 | generate(n, m, s); 19 | } 20 | -------------------------------------------------------------------------------- /archive/Simple matter/20.02.09 matter: -------------------------------------------------------------------------------- 1 | 정수 배열(int array)이 주어지면 0이 아닌 정수 순서를 유지하며 모든 0을 배열 오른쪽 끝으로 옮기시오. 단, 시간복잡도는 O(n), 공간복잡도는 O(1)여야 합니다. 2 | 3 | 4 | 5 | Given an integer array, move all the 0s to the right of the array without changing the order of non-zero elements. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: [0, 5, 0, 3, -1] 12 | 13 | Output: [5, 3, -1, 0, 0] 14 | 15 | 16 | 17 | Input: [3, 0, 3] 18 | 19 | Output: [3, 3, 0] 20 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/DP200706.cpp: -------------------------------------------------------------------------------- 1 | // 주어진 정수를 2진법으로 나타내었을때 1의 갯수를 리턴하시오. 2 | 3 | 4 | 5 | // Given an integer, count number of 1s in binary representation of an integer. 6 | 7 | 8 | 9 | // 시간 복잡도: O(log n) 10 | 11 | 12 | 13 | // input: 6 // 110 14 | 15 | // output: 2 16 | 17 | 18 | 19 | // input: 13 // 1101 20 | 21 | // output: 3 22 | 23 | #include 24 | 25 | int main() 26 | { 27 | 28 | } -------------------------------------------------------------------------------- /archive/Kimsh/코딩테스트_2: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(string s, int n) { 7 | string answer = ""; 8 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | set input; 7 | set::iterator iter; 8 | input.insert(-1), input.insert(3), input.insert(-1), input.insert(5), input.insert(4); 9 | int findNum; cin >> findNum; 10 | 11 | iter = input.begin(); 12 | for (int i = 0; i < input.size() - findNum; i++) *iter++; 13 | 14 | cout << *iter << endl; 15 | } 16 | -------------------------------------------------------------------------------- /archive/Simple matter/19.12.23 matter: -------------------------------------------------------------------------------- 1 | 피보나치 배열은 0과 1로 시작하며, 다음 피보나치 수는 바로 앞의 두 피보나치 수의 합이 된다. 정수 N이 주어지면, N보다 작은 모든 짝수 피보나치 수의 합을 구하여라. 2 | 3 | 4 | 5 | Fibonacci sequence starts with 0 and 1 where each fibonacci number is a sum of two previous fibonacci numbers. Given an integer N, find the sum of all even fibonacci numbers. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: N = 12 12 | 13 | Output: 10 // 0, 1, 2, 3, 5, 8 중 짝수인 2 + 8 = 10. 14 | -------------------------------------------------------------------------------- /archive/Simple matter/20.01.06 matter: -------------------------------------------------------------------------------- 1 | 정수(int)가 주어지면, 팰린드롬(palindrome)인지 알아내시오. 팰린드롬이란, 앞에서부터 읽으나 뒤에서부터 읽으나 같은 단어를 말합니다. 단, 정수를 문자열로 바꾸면 안됩니다. 2 | 3 | Given an integer, check if it is a palindrome. 4 | 5 | 예제) 6 | 7 | Input: 12345 8 | 9 | Output: False 10 | 11 | 12 | 13 | Input: -101 14 | 15 | Output: False 16 | 17 | 18 | 19 | Input: 11111 20 | 21 | Output: True 22 | 23 | 24 | 25 | Input: 12421 26 | 27 | Output: True 28 | -------------------------------------------------------------------------------- /archive/Simple matter/20.05.11 matter: -------------------------------------------------------------------------------- 1 | 정렬(sort)된 정수 배열과 정수 n이 주어지면, 배열안에 n이 있는지 체크하시오. 시간복잡도를 최대한 최적화하시오. 2 | 3 | 4 | 5 | Given a sorted integer array and an integer N, check if N exists in the array. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: [1, 2, 3, 7, 10], 7 12 | 13 | Output: true 14 | 15 | 16 | 17 | Input: [-5, -3, 0, 1], 0 18 | 19 | Output: true 20 | 21 |  22 | 23 | Input: [1, 4, 5, 6, 8, 9], 10 24 | 25 | Output: false 26 | -------------------------------------------------------------------------------- /archive/Simple matter/20.06.22 matter: -------------------------------------------------------------------------------- 1 | 정렬된 양수(positive integer) 배열이 주어지면, 배열 원소들의 합으로 만들수 없는 가장 작은 양수를 구하시오. 2 | 단, 시간복잡도는 O(n) 이여야 합니다. 3 | 4 | Given an array of positive integers, find the smallest positive integer that cannot be created by adding elements in the array. 5 | 6 | input: [1, 2, 3, 8] 7 | output: 7 8 | 9 | // 1 = 1 10 | // 2 = 2 11 | // 3 = 3 12 | // 4 = 1 + 3 13 | // 5 = 2 + 3 14 | // 6 = 1 + 2 + 3 15 | // 7 = 불가능 16 | -------------------------------------------------------------------------------- /archive/ayt/매프191223.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int fib(int n) { 5 | int a = 0, b = 1, c = 0; 6 | int sum = 0; 7 | while (c < n) 8 | { 9 | c = a + b; 10 | a = b; 11 | b = c; 12 | if (c % 2 == 0) 13 | { 14 | sum += c; 15 | } 16 | } 17 | return sum; 18 | } 19 | int main() 20 | { 21 | int N; 22 | cout << "Input:N = "; 23 | cin >> N; 24 | cout << "Output: " << fib(N) << endl; 25 | } 26 | -------------------------------------------------------------------------------- /archive/Simple matter/19.12.16 matter: -------------------------------------------------------------------------------- 1 | 정수 배열(int array)가 주어지면 가장 큰 이어지는 원소들의 합을 구하시오. 단, 시간복잡도는 O(n). 2 | 3 | 4 | 5 | Given an integer array, find the largest consecutive sum of elements. 6 | 7 | 8 | 예제} 9 | 10 | Input: [-1, 3, -1, 5] 11 | 12 | Output: 7 // 3 + (-1) + 5 13 | 14 | 15 | 16 | Input: [-5, -3, -1] 17 | 18 | Output: -1 // -1 19 | 20 | 21 | 22 | Input: [2, 4, -2, -3, 8] 23 | 24 | Output: 9 // 2 + 4 + (-2) + (-3) + 8 25 | -------------------------------------------------------------------------------- /archive/Simple matter/20.03.15 matter: -------------------------------------------------------------------------------- 1 | 문자열 배열(string array)이 주어지면, 제일 긴 공통된 접두사(prefix)의 길이를 찾으시오. 2 | 3 | 4 | 5 | Given an array of strings, find the longest common prefix of all strings. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: [“apple”, “apps”, “ape”] 12 | 13 | Output: 2 // “ap” 14 | 15 | 16 | 17 | Input: [“hawaii”, “happy”] 18 | 19 | Output: 2 // “ha” 20 | 21 | 22 | 23 | Input: [“dog”, “dogs”, “doge”] 24 | 25 | Output: 3 // “dog” 26 | -------------------------------------------------------------------------------- /archive/Simple matter/20.06.15 matter: -------------------------------------------------------------------------------- 1 | "./"과 "../" 이 포함된 파일 경로를 "./"과 "../"이 없는 유닉스 파일 경로로 바꾸시오. 2 | 3 | "./"는 현재의 위치를 뜻하고, "../"는 상위 디렉토리를 뜻합니다. 4 | 5 | 6 | 7 | Given a file path containing "./" and "../", convert the path to a unix standard file path that does not contain "./" and "../". 8 | 9 | 10 | 11 | input: "/usr/bin/../" 12 | 13 | output: "/usr/" 14 | 15 | 16 | 17 | input: "/usr/./bin/./test/../" 18 | 19 | output: "/usr/bin/" 20 | -------------------------------------------------------------------------------- /archive/ayt/매프200511.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int s; 5 | 6 | void check(int inp[], int n) { 7 | for (int i = 0; i < s; i++) { 8 | if (n == inp[i]) { 9 | cout << "true"; 10 | return; 11 | } 12 | } 13 | cout << "false"; 14 | } 15 | 16 | int main() { 17 | int input[] = { 1,2,3,7,10 }; 18 | int n = 7; 19 | s = sizeof(input) / sizeof(int); 20 | 21 | check(input, n); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/2diffbits.py: -------------------------------------------------------------------------------- 1 | def solution(numbers): 2 | answer = [] 3 | 4 | for number in numbers: 5 | bin_number = list('0' + bin(number)[2:]) 6 | index = ''.join(bin_number).rfind('0') 7 | bin_number[index] = '1' 8 | 9 | if number % 2 == 1: 10 | bin_number[index+1] = '0' 11 | 12 | answer.append(int(''.join(bin_number), 2)) 13 | 14 | return answer 15 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.12.20 Coding Practice No.25.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int solution(vector> clothes) { 6 | int answer = 1; 7 | unordered_map table; 8 | 9 | for (auto distribute : clothes) table[distribute[1]]++; 10 | for (auto iter = table.begin(); iter != table.end(); iter++) answer *= iter->second + 1; 11 | 12 | return --answer; 13 | } 14 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/WatermelonSugarHigh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | string main() 7 | { 8 | int n; 9 | string answer = ""; 10 | cin >> n; 11 | 12 | int size = n / 2; 13 | 14 | for(int i = 0 ; i < size; i++) 15 | { 16 | answer += "수박"; 17 | } 18 | if(n%2 != 0) 19 | answer += "수"; 20 | 21 | return answer; 22 | } 23 | -------------------------------------------------------------------------------- /archive/ayt/매프200706.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int count1(int inp) { 4 | int result = 0; 5 | while (1) { 6 | if (inp == 1) { 7 | ++result; 8 | break; 9 | } 10 | 11 | if (inp % 2 == 1) 12 | ++result; 13 | 14 | inp /= 2; 15 | } 16 | 17 | return result; 18 | } 19 | int main() { 20 | int input; 21 | cout << "input : "; 22 | cin >> input; 23 | cout << "output : " << count1(input) << endl; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /archive/Simple matter/20.02.23 matter: -------------------------------------------------------------------------------- 1 | 길이가 같은 두 문자열(string) A 와 B가 주어지면, A 가 B 로 1:1 암호화 가능한지 찾으시오. 2 | 3 | 4 | 5 | Given two strings of equal length, check if two strings can be encrypted 1 to 1. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: “EGG”, “FOO” 12 | 13 | Output: True // E->F, G->O 14 | 15 | 16 | 17 | Input: “ABBCD”, “APPLE” 18 | 19 | Output: True // A->A, B->P, C->L, D->E 20 | 21 | 22 | 23 | Input: “AAB”, “FOO” 24 | 25 | Output: False 26 | 27 | 28 | -------------------------------------------------------------------------------- /archive/ayt/매프200817.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool powerof4(int inp) { 5 | int n = 4; 6 | 7 | if (n > inp) 8 | return false; 9 | 10 | while (n <= inp) { 11 | if (n == inp) 12 | return true; 13 | n *= 4; 14 | } 15 | 16 | return false; 17 | } 18 | 19 | int main() { 20 | int input = 256; 21 | 22 | if (powerof4(input) == true) 23 | cout << "true"; 24 | else 25 | cout << "false"; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_예상대진표.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | 3 | int solution(int n, int a, int b){ 4 | int answer = 1; 5 | 6 | if(a>b) { 7 | int tmp; 8 | tmp = a; 9 | a = b; 10 | b = tmp; 11 | } 12 | 13 | while(1){ 14 | if(a+1 == b && a%2) break; 15 | 16 | a = a%2 ? a/2+1 : a/2; 17 | b = b%2 ? b/2+1 : b/2; 18 | 19 | answer++; 20 | } 21 | 22 | return answer; 23 | } 24 | -------------------------------------------------------------------------------- /archive/Simple matter/20.08.10 matter: -------------------------------------------------------------------------------- 1 | 중복된 원소가 없는 정렬된 배열이 있습니다. 이 배열에서 원소의 값이 원소의 인덱스 값과 같다면 프린트 하시오. 시간복잡도 O(log n). 2 | 3 | 4 | 5 | Given a sorted array of unique values, find an element where its value is equal to the index. 6 | 7 | 8 | 9 | input: [-30, 1, 4, 60] 10 | 11 | output: 1 // input[1] = 1 12 | 13 | 14 | 15 | input: [0, 3, 10, 60] 16 | 17 | output: 0 // input[0] = 0 18 | 19 | 20 | 21 | input: [-40, -30, -20, 3] 22 | 23 | output: 3 // input[3] = 3 24 | -------------------------------------------------------------------------------- /archive/Simple matter/19.12.30 matter: -------------------------------------------------------------------------------- 1 | 정수 n이 주어지면, n개의 여는 괄호 "("와 n개의 닫는 괄호 ")"로 만들 수 있는 괄호 조합을 모두 구하시오. (시간 복잡도 제한 없습니다). 2 | 3 | 4 | 5 | Given an integer N, find the number of possible balanced parentheses with N opening and closing brackets. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: 1 12 | 13 | Output: ["()"] 14 | 15 | 16 | 17 | Input: 2 18 | 19 | Output: ["(())", "()()"] 20 | 21 | 22 | 23 | Input: 3 24 | 25 | Output: ["((()))", "(()())", "()(())", "(())()", "()()()"] 26 | -------------------------------------------------------------------------------- /archive/YoungSeo/124num.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(int n) { 7 | string answer = ""; 8 | while(n>0){ //n이 0이될때까지 반복 9 | if(n%3==0){ //3으로 나눈 나머지=0 10 | answer.insert(0,"4"); 11 | n=n/3 - 1; 12 | } 13 | else{ //3으로 나눈 나머지가 0이 아닐때 14 | answer.insert(0,to_string(n%3)); 15 | n=n/3; 16 | } 17 | } 18 | return answer; 19 | } 20 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_멀쩡한사각형.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | 3 | long long gcd(int x,int y){ 4 | if(y==0) 5 | return x; 6 | else 7 | return gcd(y,x%y); 8 | } 9 | 10 | long long solution(int w,int h) { 11 | long long answer = (long long)w * (long long)h; 12 | 13 | if(w==h) 14 | answer -= w; 15 | else if(h==1) 16 | answer -= w; 17 | else { 18 | answer -= w + h - gcd(w,h); 19 | } 20 | 21 | return answer; 22 | } 23 | -------------------------------------------------------------------------------- /Problem/Yutae/Week1/B2839(설탕배달).cpp: -------------------------------------------------------------------------------- 1 | // https://www.acmicpc.net/problem/2839 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int N; 8 | 9 | void solution() { 10 | int res = 0; 11 | 12 | while (N>=0) { 13 | if (N % 5 == 0) { 14 | res += (N / 5); 15 | cout << res << "\n"; 16 | return; 17 | } 18 | N -= 3; 19 | res++; 20 | } 21 | 22 | cout << "-1\n"; 23 | } 24 | 25 | int main() { 26 | cin >> N; 27 | 28 | solution(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/inandout.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | def solution(enter, leave): 4 | answer = [0 for _ in range(len(enter)+1)] 5 | leave = deque(leave) 6 | 7 | room = [] 8 | for i in enter: 9 | for r in room: 10 | answer[r] += 1 11 | answer[i] += len(room) 12 | room.append(i) 13 | 14 | while leave and leave[0] in room: 15 | room.remove(leave.popleft()) 16 | 17 | return answer[1:] 18 | -------------------------------------------------------------------------------- /archive/Coding Practice/No10.txt: -------------------------------------------------------------------------------- 1 | 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 2 | 3 | 제한사항 4 | prices의 각 가격은 1 이상 10,000 이하인 자연수입니다. 5 | prices의 길이는 2 이상 100,000 이하입니다. 6 | 입출력 예 7 | prices return 8 | [1, 2, 3, 2, 3] [4, 3, 1, 1, 0] 9 | 입출력 예 설명 10 | 1초 시점의 ₩1은 끝까지 가격이 떨어지지 않았습니다. 11 | 2초 시점의 ₩2은 끝까지 가격이 떨어지지 않았습니다. 12 | 3초 시점의 ₩3은 1초뒤에 가격이 떨어집니다. 따라서 1초간 가격이 떨어지지 않은 것으로 봅니다. 13 | 4초 시점의 ₩2은 1초간 가격이 떨어지지 않았습니다. 14 | 5초 시점의 ₩3은 0초간 가격이 떨어지지 않았습니다. 15 | -------------------------------------------------------------------------------- /archive/Simple matter/20.09.07 matter: -------------------------------------------------------------------------------- 1 | 1. 2 | 단방향 연결 리스트(singly linked list)가 주어지면 총 합이 0으로 되는 연결된 노드들을 뺀 뒤 남은 노드의 값을 프린트 하시오. 3 | 4 | 5 | 6 | Given a linked list, remove consecutive nodes that sum to zero. Print the values of leftover nodes. 7 | 8 | 9 | 10 | input: 3 -> (-5) -> 5 -> 1 -> 2 -> 3 11 | 12 | output: 3 -> 1 -> 2 -> 3 13 | 14 | 15 | 16 | input: 1 -> 2 -> 3 -> 4 -> (-10) -> 5 17 | 18 | output: 5 19 | 20 | 21 | 22 | input: 10 -> (-3) -> (-4) -> (-3) -> 1 23 | 24 | output: 1 25 | -------------------------------------------------------------------------------- /archive/Coding Practice/No23.txt: -------------------------------------------------------------------------------- 1 | 124 나라가 있습니다. 124 나라에서는 10진법이 아닌 다음과 같은 자신들만의 규칙으로 수를 표현합니다. 2 | 3 | 124 나라에는 자연수만 존재합니다. 4 | 124 나라에는 모든 수를 표현할 때 1, 2, 4만 사용합니다. 5 | 예를 들어서 124 나라에서 사용하는 숫자는 다음과 같이 변환됩니다. 6 | 7 | 10진법 124 나라 10진법 124 나라 8 | 1 1 6 14 9 | 2 2 7 21 10 | 3 4 8 22 11 | 4 11 9 24 12 | 5 12 10 41 13 | 자연수 n이 매개변수로 주어질 때, n을 124 나라에서 사용하는 숫자로 바꾼 값을 return 하도록 solution 함수를 완성해 주세요. 14 | 15 | 제한사항 16 | n은 500,000,000이하의 자연수 입니다. 17 | 입출력 예 18 | n result 19 | 1 1 20 | 2 2 21 | 3 4 22 | 4 11 23 | -------------------------------------------------------------------------------- /archive/GyuMin/카펫.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/42842 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector solution(int brown, int yellow) { 8 | vector answer; 9 | 10 | int B=((brown-4)/2); 11 | 12 | for(int i=B;i>=(B-i);i--) 13 | if(i*(B-i)==yellow) 14 | { 15 | answer.push_back(i+2); 16 | answer.push_back(B-i+2); 17 | } 18 | 19 | return answer; 20 | } 21 | -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0712.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int cnt = 0; 6 | int a = 0; 7 | cout << "input : "; 8 | cin >> a; 9 | 10 | while (a>0) { 11 | a % 2 == 1 ? cnt += 1:cnt+=0; 12 | a = a / 2; 13 | } 14 | 15 | cout << "output : " << cnt<<"\n"; 16 | 17 | return 0; 18 | } 19 | /*주어진 정수를 2진법으로 나타내었을때 1의 갯수를 리턴하시오. 20 | 21 | 시간 복잡도: O(log n) 22 | 23 | input: 6 // 110 24 | output: 2 25 | 26 | input: 13 // 1101 27 | output: 3 28 | */ 29 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.03.21 Coding Practice No.49.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12909 2 | 3 | #include 4 | using namespace std; 5 | 6 | bool solution(string s){ 7 | int leftCount = 0; 8 | 9 | for (int i = 0; i < s.size(); i++) 10 | if (s[i] == '(') leftCount++; 11 | else 12 | if (leftCount == 0) return false; 13 | else leftCount--; 14 | 15 | if (leftCount == 0) return true; 16 | else return false; 17 | } 18 | -------------------------------------------------------------------------------- /archive/ayt/백준_ SMUPC의등장.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solution(string input) { 8 | for (auto elem : input) { 9 | int asc = elem; 10 | int sum = 0; 11 | while (asc > 0) { 12 | sum += asc % 10; 13 | asc /= 10; 14 | } 15 | for (int i = 0; i < sum; i++) 16 | cout << elem; 17 | cout << endl; 18 | } 19 | } 20 | 21 | int main() { 22 | string input; 23 | 24 | cin >> input; 25 | 26 | solution(input); 27 | } 28 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/weightloss.py: -------------------------------------------------------------------------------- 1 | import itertools # 순열 생성 라이브러리 2 | 3 | N, K = map(int,input().split()) 4 | nums = list(map(int,input().split())) 5 | 6 | 7 | count = 0 8 | for kit in list(itertools.permutations((nums))): 9 | deadline = 500 10 | # 각 순열을 순회하며 3대 계산 11 | for k in kit: 12 | deadline = deadline - K + k 13 | # 순회하면서 한번이라도 500밑으로 내려가면 break 14 | if deadline < 500: 15 | break 16 | if deadline > 500: 17 | count += 1 18 | 19 | print(count) -------------------------------------------------------------------------------- /archive/MoonSeong/210321rightBrackets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool solution(string s) 7 | { 8 | bool answer = true; 9 | int v=0; 10 | for(int i=0; i right) return 0; 6 | int &ret = cache[left][right]; 7 | if(ret != EMPTY) return ret; 8 | 9 | ret = max(board[left] - play(left + 1, right), board[right] - play(left,right -1)); 10 | 11 | if(right - left + 1 >= 2) { 12 | ret = max(ret, -play(left + 2, right)); 13 | ret = max(ret, -play(left, right -2)); 14 | } 15 | } -------------------------------------------------------------------------------- /archive/YoungSeo/cloth.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(vector> clothes) { 8 | map m; 9 | int answer = 1; 10 | //종류별로 분류 11 | for(int i = 0; isecond) + 1); 17 | } 18 | 19 | return answer - 1; //아무것도 안입는 경우 1 제외 20 | } 21 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_멀리뛰기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | long long solution(int n) { 7 | long long answer = 0; 8 | vector tmp(n+1); 9 | tmp[1]=1; 10 | tmp[2]=2; 11 | 12 | if(n==1) 13 | return tmp[1]; 14 | if(n==2) 15 | return tmp[2]; 16 | 17 | for(int i=3;i<=n;++i){ 18 | tmp[i]=(tmp[i-1]+tmp[i-2])%1234567; 19 | } 20 | answer=tmp[n]; 21 | 22 | return answer; 23 | } 24 | 25 | //약간 문제가 이상함 26 | -------------------------------------------------------------------------------- /archive/MoonSeong/carpet.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] solution(int brown, int yellow) { 3 | int[] answer = new int[2]; 4 | int x, y; 5 | 6 | for (y = 1; y < ((brown + 4) / 2); y++) { 7 | x = (brown + 4) / 2 - y; 8 | if ( (x * y) == yellow + brown ) { 9 | answer[0] = x; 10 | answer[1] = y; 11 | break; 12 | } 13 | } 14 | 15 | 16 | return answer; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /archive/Simple matter/20.03.22 matter: -------------------------------------------------------------------------------- 1 | 링크드 리스트(linked list)의 머리 노드(head node)와 정수 N이 주어지면, 끝에서 N번째 노드(node)를 제거하고 머리 노드(head node)를 리턴하시오. 2 | 3 | 단, 리스트를 한번만 돌면서 풀어야합니다. N은 리스트 길이보다 크지 않습니다. 4 | 5 | 6 | 7 | Given a head node of a singly linked list, remove the Nth last element and return the head node. 8 | 9 | 10 | 11 | 예제) 12 | 13 | Input: 1->2->3->4->5, N=2 14 | 15 | Output: 1->2->3->5 16 | 17 | 18 | 19 | Input: 1->2->3, N=3 20 | 21 | Output: 2->3 22 | 23 | 24 | 25 | Input: 1, N=1 26 | 27 | Output: null 28 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/IntegerTriagle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(vector> triangle) { 8 | int answer = 0; 9 | int *cache = new int[pow(2, triangle.size()-1)]; 10 | 11 | for (int i = 0; i < triangle.size(); i++) 12 | { 13 | for (int j = 0; j < triangle[i].size; j++) 14 | { 15 | /* code */ 16 | } 17 | 18 | } 19 | 20 | 21 | return answer; 22 | } -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/bruteforce/BP-Carpet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(int brown, int yellow) { 7 | vector answer; 8 | int sumnum = brown + yellow; 9 | for(int i = 1; i < sumnum; i++) { 10 | if(sumnum % i == 0 && sumnum / i <= i && yellow % (i-2) == 0) { 11 | answer.push_back(i); 12 | answer.push_back(sumnum / i); 13 | break; 14 | } 15 | } 16 | return answer; 17 | } -------------------------------------------------------------------------------- /archive/Coding Practice/No26.txt: -------------------------------------------------------------------------------- 1 | 정수 n이 매개변수로 주어집니다. 다음 그림과 같이 밑변의 길이와 높이가 n인 삼각형에서 맨 위 꼭짓점부터 반시계 방향으로 달팽이 채우기를 진행한 후, 첫 행부터 마지막 행까지 모두 순서대로 합친 새로운 배열을 return 하도록 solution 함수를 완성해주세요. 2 | 3 | examples.png 4 | 5 | 제한사항 6 | n은 1 이상 1,000 이하입니다. 7 | 입출력 예 8 | n result 9 | 4 [1,2,9,3,10,8,4,5,6,7] 10 | 5 [1,2,12,3,13,11,4,14,15,10,5,6,7,8,9] 11 | 6 [1,2,15,3,16,14,4,17,21,13,5,18,19,20,12,6,7,8,9,10,11] 12 | 입출력 예 설명 13 | 입출력 예 #1 14 | 15 | 문제 예시와 같습니다. 16 | 입출력 예 #2 17 | 18 | 문제 예시와 같습니다. 19 | 입출력 예 #3 20 | 21 | 문제 예시와 같습니다. 22 | -------------------------------------------------------------------------------- /archive/Coding Practice/No53.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12949 2 | 3 | 문제 설명 4 | 2차원 행렬 arr1과 arr2를 입력받아, arr1에 arr2를 곱한 결과를 반환하는 함수, solution을 완성해주세요. 5 | 6 | 제한 조건 7 | 행렬 arr1, arr2의 행과 열의 길이는 2 이상 100 이하입니다. 8 | 행렬 arr1, arr2의 원소는 -10 이상 20 이하인 자연수입니다. 9 | 곱할 수 있는 배열만 주어집니다. 10 | 입출력 예 11 | arr1 arr2 return 12 | [[1, 4], [3, 2], [4, 1]] [[3, 3], [3, 3]] [[15, 15], [15, 15], [15, 15]] 13 | [[2, 3, 2], [4, 2, 4], [3, 1, 4]] [[5, 4, 3], [2, 4, 1], [3, 1, 1]] [[22, 22, 11], [36, 28, 18], [29, 20, 14]] 14 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.02.07 Coding Practice No.39.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12915 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int standard; 8 | 9 | bool cmp(string& a, string& b) { 10 | if (a[standard] == b[standard]) return a < b; 11 | else return a[standard] < b[standard]; 12 | } 13 | 14 | vector solution(vector strings, int n) { 15 | standard = n; 16 | sort(strings.begin(), strings.end(), cmp); 17 | return strings; 18 | } 19 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/binarychange.py: -------------------------------------------------------------------------------- 1 | def solution(s): 2 | count = 1 3 | zerocount = 0 4 | size = 0 5 | 6 | while s != '1' : 7 | temp = '' 8 | for i in s: 9 | if i == '1' : 10 | temp += i 11 | else : 12 | zerocount += 1 13 | 14 | size = len(temp) 15 | if size > 1: 16 | count += 1 17 | 18 | s = str(format(size, 'b')) 19 | 20 | answer = [count, zerocount] 21 | return answer -------------------------------------------------------------------------------- /archive/ayt/매프200315.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | char input1[] = "apple"; 7 | char input2[] = "apps"; 8 | char input3[] = "ape"; 9 | int Output1 = 0; 10 | char Output2[5] = { " ", }; 11 | 12 | for (int i = 0; i < 5; i++) { 13 | if (input1[i] == input2[i] && input1[i] == input3[i] && input2[i] == input3[i]) { 14 | Output2[i] = input1[i]; 15 | Output1++; 16 | } 17 | } 18 | 19 | cout << "Output: " << Output1 << " // "<< Output2 << endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /archive/SeHyeon/19.12.16 matter(Simple.ver).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define SIZE 5 4 | 5 | int calc(int arr[]) { 6 | int maxSum = arr[0]; 7 | int currentSum = arr[0]; 8 | for (int i = 1; i < SIZE; i++) { 9 | currentSum = currentSum + arr[i] > arr[i] ? currentSum + arr[i] : arr[i]; 10 | maxSum = currentSum > maxSum ? currentSum : maxSum; 11 | } 12 | return maxSum; 13 | } 14 | 15 | int main() 16 | { 17 | int arr[SIZE]; for (int i = 0; i < SIZE; i++) cin >> arr[i]; 18 | cout << calc(arr); 19 | } 20 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/DP200824.cpp: -------------------------------------------------------------------------------- 1 | // 이진탐색트리안에 X보다 크고 Y보다 작은 모든 노드 값을 프린트 하시오. 2 | 3 | 4 | 5 | // Given a binary search tree, print all node values that are bigger than X and smaller than Y. 6 | 7 | #include 8 | using namespace std; 9 | 10 | class NODE 11 | { 12 | private: 13 | int value; 14 | NODE* right; 15 | NODE* left; 16 | public: 17 | NODE(); 18 | ~NODE(); 19 | }; 20 | 21 | NODE::NODE() 22 | { 23 | } 24 | 25 | NODE::~NODE() 26 | { 27 | } 28 | 29 | int main() { 30 | NODE node; 31 | } -------------------------------------------------------------------------------- /archive/YoungSeo/문자열내맘대로정렬.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int x; 8 | 9 | bool Ssort(string a, string b){ 10 | if(a.at(x)!=b.at(x)){ 11 | return a.at(x) < b.at(x); 12 | }else{ 13 | return a < b; 14 | } 15 | } 16 | 17 | vector solution(vector strings, int n) { 18 | vector answer; 19 | answer = strings; 20 | x = n; 21 | sort(answer.begin(),answer.end(),Ssort); 22 | return answer; 23 | } 24 | -------------------------------------------------------------------------------- /archive/Kimsh/보글게임 예제: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | const int dx[8] = { -1,-1,-1,1,1,1,0,0 }; 7 | const int dy[8] = { -1,0,1,-1,0,1,-1,1 }; 8 | 9 | //5*5의 보글게임판의 해당 위치에서 주어진 단어가 시작하는지를 반환 10 | bool hasWord(int y, int x, const string&word) { 11 | //기저 사례 1: 시작 위치가 범위 밖이면 무조건 실패 12 | if (!_In_range_(y) == NULL)return false; 13 | //기저 사례 2 : 첫 글자가 일치하지 않으면 실패 14 | } 15 | 16 | int main(void) { 17 | 18 | 19 | 20 | getchar(); 21 | getchar(); 22 | return 0; 23 | } 24 | //하다 맒,,,, 25 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-7 Morse Code 9-7(Full Serach Ver2).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int skip; 5 | 6 | void generate(int n, int m, string s) { 7 | if (skip < 0) return; 8 | if (n == 0 && m == 0) { 9 | if(skip == 0) cout << s << endl; 10 | skip--; 11 | return; 12 | } 13 | 14 | if (n > 0) generate(n - 1, m, s + "-"); 15 | if (m > 0) generate(n, m - 1, s + "o"); 16 | } 17 | 18 | int main() { 19 | string s = ""; 20 | int k; cin >> k; skip = k - 1; 21 | int n, m; cin >> n >> m; 22 | generate(n, m, s); 23 | } 24 | -------------------------------------------------------------------------------- /archive/GyuMin/문자열 내 맘대로.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/12915 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int x; 9 | 10 | bool cmp(string a, string b) 11 | { 12 | if (a[x] != b[x]) 13 | return a[x] < b[x]; 14 | 15 | else 16 | return a < b; 17 | } 18 | 19 | vector solution(vector strings, int n) 20 | { 21 | x = n; 22 | 23 | sort(strings.begin(), strings.end(), cmp); 24 | 25 | return strings; 26 | } 27 | -------------------------------------------------------------------------------- /archive/MoonSeong/210606jumpNTeleport(F).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int powI(int n, int exp) { 7 | return (int)pow((double)n, (double)exp); 8 | } 9 | 10 | int solution(int n) 11 | { 12 | int ans = 0; 13 | 14 | int i = 0; 15 | int lower, higher; 16 | 17 | while (powI(2, i) <= n) 18 | i++; 19 | 20 | lower = n - powI(2, i-1); 21 | higher = powI(2, i) - n; 22 | 23 | ans = lower > higher ? lower : higher; 24 | 25 | return ans; 26 | } 27 | -------------------------------------------------------------------------------- /archive/Coding Practice/No12.txt: -------------------------------------------------------------------------------- 1 | 문제 설명 2 | 한자리 숫자가 적힌 종이 조각이 흩어져있습니다. 흩어진 종이 조각을 붙여 소수를 몇 개 만들 수 있는지 알아내려 합니다. 3 | 4 | 각 종이 조각에 적힌 숫자가 적힌 문자열 numbers가 주어졌을 때, 종이 조각으로 만들 수 있는 소수가 몇 개인지 return 하도록 solution 함수를 완성해주세요. 5 | 6 | 제한사항 7 | numbers는 길이 1 이상 7 이하인 문자열입니다. 8 | numbers는 0~9까지 숫자만으로 이루어져 있습니다. 9 | 013은 0, 1, 3 숫자가 적힌 종이 조각이 흩어져있다는 의미입니다. 10 | 입출력 예 11 | numbers return 12 | 17 3 13 | 011 2 14 | 입출력 예 설명 15 | 예제 #1 16 | [1, 7]으로는 소수 [7, 17, 71]를 만들 수 있습니다. 17 | 18 | 예제 #2 19 | [0, 1, 1]으로는 소수 [11, 101]를 만들 수 있습니다. 20 | 21 | 11과 011은 같은 숫자로 취급합니다. 22 | -------------------------------------------------------------------------------- /archive/ayt/매프200209.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void change(int* in) { 6 | int index = 0; 7 | for (int i = 0; i < 5; i++) { 8 | if (in[i] != 0) { 9 | swap(in[i],in[index]); 10 | index++; 11 | } 12 | } 13 | } 14 | 15 | int main() 16 | { 17 | int input[] = { 0,5,0,3,-1 }; 18 | for (int i = 0; i < 5; i++) 19 | cout << " " << input[i]; 20 | change(input); 21 | cout << "\n"; 22 | for (int i = 0; i < 5; i++) 23 | cout << " " << input[i]; 24 | cout << "\n"; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_카펫.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(int brown, int yellow) { 7 | vector answer; 8 | int n = brown+yellow;; //가로, 세로 9 | 10 | for(int i=1;i*i<=n;++i){ 11 | if(n%i==0 && yellow==(i-2)*(n/i-2)){ //brown + yellow == h * v 12 | answer.push_back(n/i); //yellow == (h - 2) * (v - 2) 13 | answer.push_back(i); 14 | } 15 | } 16 | 17 | return answer; 18 | } 19 | -------------------------------------------------------------------------------- /archive/Coding Practice/No55.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12952?language=cpp 2 | 3 | N-Queen 4 | 문제 설명 5 | 가로, 세로 길이가 n인 정사각형으로된 체스판이 있습니다. 체스판 위의 n개의 퀸이 서로를 공격할 수 없도록 배치하고 싶습니다. 6 | 7 | 예를 들어서 n이 4인경우 다음과 같이 퀸을 배치하면 n개의 퀸은 서로를 한번에 공격 할 수 없습니다. 8 | 9 | Imgur 10 | Imgur 11 | 12 | 체스판의 가로 세로의 세로의 길이 n이 매개변수로 주어질 때, n개의 퀸이 조건에 만족 하도록 배치할 수 있는 방법의 수를 return하는 solution함수를 완성해주세요. 13 | 14 | 제한사항 15 | 퀸(Queen)은 가로, 세로, 대각선으로 이동할 수 있습니다. 16 | n은 12이하의 자연수 입니다. 17 | 입출력 예 18 | n result 19 | 4 2 20 | 입출력 예 설명 21 | 입출력 예 #1 22 | 문제의 예시와 같습니다. 23 | -------------------------------------------------------------------------------- /archive/SongChiHoon/OnBook/knapsackproblem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int n, capacity; 5 | int volume[100], need[100]; 6 | int cache [1001][100]; 7 | string name[100]; 8 | 9 | int pack(int capacity, int item) { 10 | if(item == n) return 0; 11 | int &ret = cache[capacity][item]; 12 | if(ret != -1) return ret; 13 | 14 | ret = pack(capacity, item + 1); 15 | 16 | if(capacity >= volume[item]) { 17 | ret = max(ret, pack(capacity - volume[item], item + 1) + need[item]); 18 | 19 | return ret; 20 | } 21 | } -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_시저암호.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(string s, int n) { 7 | string answer = ""; 8 | 9 | for(int i = 0;i < s.size();i++) { 10 | if(n == 0) break; 11 | else if(s[i] == ' ') continue; 12 | else 13 | for(int j = 0;j < n;j++) { 14 | if(s[i] == 90 || s[i] == 122) 15 | s[i] -= 26; 16 | s[i]++; 17 | } 18 | } 19 | answer = s; 20 | 21 | return answer; 22 | } 23 | -------------------------------------------------------------------------------- /archive/MoonSeong/210425matMult(compileError).py: -------------------------------------------------------------------------------- 1 | def solution(arr1, arr2): 2 | answer = [[]] # size: arr2x x arr1y 3 | 4 | arr1x = len(arr1[0]) 5 | arr1y = len(arr1) 6 | arr2x = len(arr2[0]) 7 | arr2y = len(arr2) 8 | 9 | for ypos in range(arr1y): 10 | for xpos in range(arr2x): 11 | element = 0 12 | # get element 13 | for x in range(arr1[ypos]): 14 | element += arr1[ypos][x] * arr2[x][ypos] 15 | answer[ypos].append(element) 16 | 17 | 18 | return answer 19 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_완주하지못한선수_hashset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | string solution(vector participant, vector completion) { 8 | string answer = ""; 9 | unordered_multiset hashset; 10 | 11 | for(auto alem : participant ){ 12 | hashset.insert(alem); 13 | } 14 | for(auto alem : completion){ 15 | hashset.erase(hashset.find(alem)); 16 | } 17 | 18 | answer = *hashset.begin(); 19 | 20 | return answer; 21 | } 22 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.07.06 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int solution(int input) { 6 | stack binary; 7 | int result = 0; 8 | 9 | while (true) { 10 | if (input == 1) { 11 | binary.push(1); 12 | break; 13 | } 14 | binary.push(input % 2); 15 | input /= 2; 16 | } 17 | 18 | while (!binary.empty()) { 19 | if (binary.top() == 1) ++result; 20 | binary.pop(); 21 | } 22 | return result; 23 | } 24 | 25 | int main() { 26 | int input; cin >> input; 27 | 28 | cout << solution(input) << endl; 29 | } 30 | -------------------------------------------------------------------------------- /archive/GyuMin/124.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/12899 2 | #include 3 | using namespace std; 4 | string solution(int n) 5 | { 6 | string answer = ""; 7 | for (;;) 8 | { 9 | switch (n % 3) 10 | { 11 | case 0: 12 | answer = "4" + answer; 13 | break; 14 | case 1: 15 | answer = "1" + answer; 16 | break; 17 | case 2: 18 | answer = "2" + answer; 19 | break; 20 | } 21 | if (n <= 3) 22 | break; 23 | else if (!(n % 3)) 24 | n = (n - 1) / 3; 25 | else 26 | n = n / 3; 27 | } 28 | return answer; 29 | } 30 | -------------------------------------------------------------------------------- /archive/GyuMin/꼴등.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/42576 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | string solution(vector participant, vector completion) 9 | { 10 | sort(participant.begin(), participant.end()); 11 | sort(completion.begin(),completion.end()); 12 | 13 | for(int i = 0 ; i <= participant.size(); i++) 14 | { 15 | if(participant[i] != completion[i]) 16 | { 17 | return participant[i]; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-21 numberGame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int EMPTY = -987654321; 5 | int n, board[50]; 6 | int cache[50][50]; 7 | 8 | int play(int left, int right) { 9 | if (left > right) return 0; 10 | 11 | int& ret = cache[left][right]; 12 | if (ret != EMPTY) return ret; 13 | 14 | ret = max(board[left] - play(left + 1, right), board[right] - play(left, right - 1); 15 | if (right - left + 1 >= 2) { 16 | ret = max(ret, -play(left + 2, right)); 17 | ret = max(ret, -play(left, right - 2)); 18 | } 19 | 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /archive/Coding Practice/No14.txt: -------------------------------------------------------------------------------- 1 | 문제 설명 2 | Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. 3 | 4 | carpet.png 5 | 6 | Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 갈색으로 색칠된 격자의 개수는 기억했지만, 전체 카펫의 크기는 기억하지 못했습니다. 7 | 8 | Leo가 본 카펫에서 갈색 격자의 수 brown, 노란색 격자의 수 yellow가 매개변수로 주어질 때 카펫의 가로, 세로 크기를 순서대로 배열에 담아 return 하도록 solution 함수를 작성해주세요. 9 | 10 | 제한사항 11 | 갈색 격자의 수 brown은 8 이상 5,000 이하인 자연수입니다. 12 | 노란색 격자의 수 yellow는 1 이상 2,000,000 이하인 자연수입니다. 13 | 카펫의 가로 길이는 세로 길이와 같거나, 세로 길이보다 깁니다. 14 | 입출력 예 15 | brown yellow return 16 | 10 2 [4, 3] 17 | 8 1 [3, 3] 18 | 24 24 [8, 6] 19 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.07.25 Coding Practice No.69.py: -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/21735 2 | 3 | N, M = map(int, input().split()) 4 | a_seq = list(map(int, input().split())) 5 | 6 | def dfs(size, time, pos): 7 | print(time, " -- ", size); 8 | #기저사례 9 | if (time == 0): 10 | return; 11 | #1번 - 굴림 12 | if (pos + 1 < N): 13 | dfs(size + a_seq[pos], time - 1, pos + 1) 14 | #2번 - 던짐 15 | if (pos + 2 < N): 16 | dfs(int(size / 2) + a_seq[pos + 2], time - 1, pos + 2) 17 | 18 | ans = 1 19 | dfs(1, M, 0) 20 | print(ans) 21 | 22 | -------------------------------------------------------------------------------- /archive/Coding Practice/No15.txt: -------------------------------------------------------------------------------- 1 | 문제 설명 2 | 주어진 숫자 중 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하려고 합니다. 숫자들이 들어있는 배열 nums가 매개변수로 주어질 때, nums에 있는 숫자들 중 서로 다른 3개를 골라 더했을 때 소수가 되는 경우의 개수를 return 하도록 solution 함수를 완성해주세요. 3 | 4 | 제한사항 5 | nums에 들어있는 숫자의 개수는 3개 이상 50개 이하입니다. 6 | nums의 각 원소는 1 이상 1,000 이하의 자연수이며, 중복된 숫자가 들어있지 않습니다. 7 | 입출력 예 8 | nums result 9 | [1,2,3,4] 1 10 | [1,2,7,6,4] 4 11 | 입출력 예 설명 12 | 입출력 예 #1 13 | [1,2,4]를 이용해서 7을 만들 수 있습니다. 14 | 15 | 입출력 예 #2 16 | [1,2,4]를 이용해서 7을 만들 수 있습니다. 17 | [1,4,6]을 이용해서 11을 만들 수 있습니다. 18 | [2,4,7]을 이용해서 13을 만들 수 있습니다. 19 | [4,6,7]을 이용해서 17을 만들 수 있습니다. 20 | -------------------------------------------------------------------------------- /archive/Coding Practice/No8.txt: -------------------------------------------------------------------------------- 1 | 효진이는 멀리 뛰기를 연습하고 있습니다. 효진이는 한번에 1칸, 또는 2칸을 뛸 수 있습니다. 칸이 총 4개 있을 때, 효진이는 2 | (1칸, 1칸, 1칸, 1칸) 3 | (1칸, 2칸, 1칸) 4 | (1칸, 1칸, 2칸) 5 | (2칸, 1칸, 1칸) 6 | (2칸, 2칸) 7 | 의 5가지 방법으로 맨 끝 칸에 도달할 수 있습니다. 멀리뛰기에 사용될 칸의 수 n이 주어질 때, 효진이가 끝에 도달하는 방법이 몇 가지인지 알아내, 여기에 1234567를 나눈 나머지를 리턴하는 함수, solution을 완성하세요. 예를 들어 4가 입력된다면, 5를 return하면 됩니다. 8 | 9 | 제한 사항 10 | n은 1 이상, 2000 이하인 정수입니다. 11 | 입출력 예 12 | n result 13 | 4 5 14 | 3 3 15 | 입출력 예 설명 16 | 입출력 예 #1 17 | 위에서 설명한 내용과 같습니다. 18 | 19 | 입출력 예 #2 20 | (2칸, 1칸) 21 | (1칸, 2칸) 22 | (1칸, 1칸, 1칸) 23 | 총 3가지 방법으로 멀리 뛸 수 있습니다. 24 | -------------------------------------------------------------------------------- /archive/MoonSeong/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(void) { 6 | string input; 7 | cin >> input; 8 | 9 | for (int i = 0; i < input.length(); i++) { 10 | char ch = input[i]; 11 | int n = 0; 12 | //get n 13 | n += ch / 100; 14 | ch -= 100 * (ch / 100); 15 | n += ch / 10; 16 | ch -= 10 * (ch / 10); 17 | n += ch; 18 | //print for n 19 | while (n-- > 0) 20 | cout << input[i]; 21 | cout << endl; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /archive/SeHyeon/19.12.08 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define SIZE 5 4 | 5 | int main() 6 | { 7 | int arr[SIZE] = {1,2,3,4,5}; 8 | int tmp1[SIZE], tmp2[SIZE]; 9 | 10 | int accumulate = 1; 11 | 12 | for (int i = 0; i < SIZE; i++) { 13 | tmp1[i] = accumulate; 14 | accumulate *= arr[i]; 15 | } 16 | 17 | accumulate = 1; 18 | 19 | for (int i = SIZE - 1; i >= 0; i--) { 20 | tmp2[i] = accumulate; 21 | accumulate *= arr[i]; 22 | } 23 | cout << "output : "; 24 | for (int i = 0; i < SIZE; i++) 25 | cout << tmp1[i] * tmp2[i] << " "; 26 | } 27 | -------------------------------------------------------------------------------- /archive/Coding Practice/No67.txt(BAEKJOON): -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/11053 2 | 3 | 가장 긴 증가하는 부분 수열 4 | 시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율 5 | 1 초 256 MB 76983 29798 19606 36.963% 6 | 문제 7 | 수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오. 8 | 9 | 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {10, 20, 10, 30, 20, 50} 이고, 길이는 4이다. 10 | 11 | 입력 12 | 첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000)이 주어진다. 13 | 14 | 둘째 줄에는 수열 A를 이루고 있는 Ai가 주어진다. (1 ≤ Ai ≤ 1,000) 15 | 16 | 출력 17 | 첫째 줄에 수열 A의 가장 긴 증가하는 부분 수열의 길이를 출력한다. 18 | 19 | 예제 입력 1 20 | 6 21 | 10 20 10 30 20 50 22 | 예제 출력 1 23 | 4 24 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.02.23 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | char matching[26]; memset(matching, NULL, sizeof(matching)); 6 | bool answer = true; 7 | 8 | string input, compare; 9 | cin >> input >> compare; 10 | 11 | for (int i = 0; i < input.length(); i++) { 12 | if (matching[input[i] - 65]) { 13 | if (matching[input[i] - 65] == compare[i]) continue; 14 | else answer = false; 15 | } 16 | else matching[input[i] - 65] = compare[i]; 17 | } 18 | 19 | if(answer) cout << "True" << endl; 20 | else cout << "False" << endl; 21 | } 22 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.01.17 Coding Practice No.33.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | vector solution(int n, vector arr1, vector arr2) { 6 | vector answer; 7 | for (int i = 0; i < n; i++) { 8 | bitset<16> bs1 = arr1[i], bs2 = arr2[i]; 9 | string input = "", tmp; 10 | 11 | bs1 = bs1 | bs2; 12 | tmp = bs1.to_string(); 13 | for (int j = 16 - n; j < 16; j++) input += (tmp[j] == '1' ? '#' : ' '); 14 | answer.push_back(input); 15 | } 16 | return answer; 17 | } 18 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.09.05 Coding Practice No.79.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/42885 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int solution(vector people, int limit) { 8 | int answer = 0; 9 | int head = 0, tail = people.size() - 1; 10 | 11 | sort(people.begin(), people.end()); 12 | while (head <= tail) { 13 | if (people[head] + people[tail] <= limit) 14 | head++, tail--; 15 | else 16 | tail--; 17 | answer++; 18 | } 19 | 20 | return answer; 21 | } 22 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-15 shortestPath2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int n, dist[MAX][MAX]; 5 | double cache[MAX][1 << MAX]; 6 | 7 | double shortestPath2(int here, int visited) { 8 | if (visited == (1 << n) - 1) return dist[here][0]; 9 | 10 | double& ret = cache[here][visited]; 11 | if (ret >= 0) return ret; 12 | ret = INF; 13 | 14 | for (int next = 0; next < n; ++next) { 15 | if (visited & (1 << next)) continue; 16 | double cand = dist[here][next] + shortestPath2(next, visited + (1 << next)); 17 | ret = min(ret, cand); 18 | } 19 | return ret; 20 | } 21 | -------------------------------------------------------------------------------- /archive/YoungSeo/비밀지도.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector solution(int n, vector arr1, vector arr2) { 8 | vector answer; 9 | string s3 = ""; 10 | 11 | for (int i = 0; i < n; i++) { 12 | s3 = bitset<16>(arr1[i] | arr2[i]).to_string(); 13 | for (int j = 16 - n; j < 16; j++) { 14 | if (s3[j] == '1') s3[j] = '#'; 15 | else s3[j] = ' '; 16 | } 17 | answer.push_back(s3.substr(16-n, 16)); 18 | } 19 | return answer; 20 | } 21 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.04.27 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string arrayCycle(int* input, int size) { 5 | int nextIndex = 0; 6 | for (int i = 0; i < size; i++) { 7 | nextIndex = input[nextIndex]; 8 | if (nextIndex == 0 && i < size - 1) return "False"; 9 | } 10 | if (nextIndex == 0) return "True"; 11 | else return "False"; 12 | } 13 | 14 | int main() { 15 | int input[] = { 1, 2, 4, 0, 3 }; 16 | //int input[] = { 1, 4, 5, 0, 3, 2 }; 17 | /*int input[] = { 1, 2, 2, 0 };*/ 18 | 19 | cout << arrayCycle(input, sizeof(input) / sizeof(input[0])) << endl; 20 | } 21 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.10.14 Coding Practice No.15.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isDecimal(int num) { 4 | if (num < 2) return false; 5 | for (int i = 2; i * i <= num; i++) 6 | if (num % i == 0) return false; 7 | return true; 8 | } 9 | 10 | int solution(std::vector nums) { 11 | int answer = 0; 12 | for (int i = 0; i < nums.size(); i++) 13 | for (int j = i + 1; j < nums.size(); j++) 14 | for (int k = j + 1; k < nums.size(); k++) 15 | if(isDecimal(nums[i] + nums[j] + nums[k])) answer++; 16 | return answer; 17 | } 18 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_비밀지도.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(int n, vector arr1, vector arr2) { 7 | vector answer; 8 | 9 | for (int i = 0; i < n; ++i) { 10 | string tmp; 11 | arr1[i] = arr1[i] | arr2[i]; 12 | while (arr1[i] > 0) { 13 | arr1[i] % 2 ? tmp = '#' + tmp : tmp = ' ' + tmp; 14 | arr1[i] /= 2; 15 | } 16 | while (tmp.size() != n) tmp = ' ' + tmp; 17 | answer.push_back(tmp); 18 | } 19 | 20 | return answer; 21 | } 22 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_완주하지못한선수.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | string solution(vector participant, vector completion) { 8 | string answer = ""; 9 | 10 | sort(participant.begin(), participant.end()); 11 | sort(completion.begin(), completion.end()); 12 | 13 | for(int i = 0 ; i < participant.size() ; i++) { 14 | if(participant[i] != completion[i]) { 15 | answer = participant[i]; 16 | break; 17 | } 18 | } 19 | 20 | return answer; 21 | } 22 | -------------------------------------------------------------------------------- /archive/Coding Practice/No49.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12909 2 | 3 | 문제 설명 4 | 괄호가 바르게 짝지어졌다는 것은 '(' 문자로 열렸으면 반드시 짝지어서 ')' 문자로 닫혀야 한다는 뜻입니다. 예를 들어 5 | 6 | "()()" 또는 "(())()" 는 올바른 괄호입니다. 7 | ")()(" 또는 "(()(" 는 올바르지 않은 괄호입니다. 8 | '(' 또는 ')' 로만 이루어진 문자열 s가 주어졌을 때, 문자열 s가 올바른 괄호이면 true를 return 하고, 올바르지 않은 괄호이면 false를 return 하는 solution 함수를 완성해 주세요. 9 | 10 | 제한사항 11 | 문자열 s의 길이 : 100,000 이하의 자연수 12 | 문자열 s는 '(' 또는 ')' 로만 이루어져 있습니다. 13 | 입출력 예 14 | s answer 15 | "()()" true 16 | "(())()" true 17 | ")()(" false 18 | "(()(" false 19 | 입출력 예 설명 20 | 입출력 예 #1,2,3,4 21 | 문제의 예시와 같습니다. 22 | -------------------------------------------------------------------------------- /archive/YoungSeo/완주못한선수.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | string solution(vector participant, vector completion) { 9 | std::sort(participant.begin(), participant.end()); 10 | std::sort(completion.begin(), completion.end()); 11 | 12 | int num = 0; 13 | 14 | for(int i=0; i < participant.size(); i++){ 15 | if( participant[i] != completion[i]){ 16 | return participant[i]; 17 | } 18 | } 19 | 20 | return participant[participant.size()-1]; 21 | } 22 | -------------------------------------------------------------------------------- /archive/ayt/매프200608.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int input[] = { 2,4,6,8 }; 5 | 6 | int tmpGcd(int a, int b) { 7 | if (b == 0) 8 | return a; 9 | if (a < b) { 10 | int tmp = a; 11 | a = b; 12 | b = tmp; 13 | } 14 | while (b != 0) { 15 | int tmp = b; 16 | b %= a; 17 | a = tmp; 18 | } 19 | 20 | return a; 21 | } 22 | 23 | int findGcd() { 24 | int nowgcd = 0; 25 | 26 | for (int i : input) { 27 | nowgcd = tmpGcd(i, nowgcd); 28 | } 29 | 30 | return nowgcd; 31 | } 32 | 33 | int main() { 34 | cout << "output : " << findGcd(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /archive/ayt/매프200810.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int findEqual(int *inp, int n) { 5 | int start = 0; 6 | int end = n - 1; 7 | int mid, key; 8 | 9 | while (end - start >= 0) { 10 | mid = (start + end) / 2; 11 | key = mid; 12 | 13 | if (inp[mid] == key) 14 | return key; 15 | else if (inp[mid] > key) 16 | end = mid - 1; 17 | else 18 | start = mid + 1; 19 | } 20 | } 21 | 22 | int main() { 23 | int input[] = { -30,1,4,60 }; 24 | int size = sizeof(input) / sizeof(int); 25 | 26 | cout << "output : " << findEqual(input, size); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_구명보트.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(vector people, int limit) { 8 | int answer = 0; 9 | 10 | sort(people.begin(), people.end()); 11 | 12 | int start = 0; 13 | int end = people.size()-1; 14 | 15 | while(start<=end) { 16 | if(people[start] + people[end]<=limit) { 17 | start++; 18 | end--; 19 | } 20 | else 21 | end--; 22 | 23 | answer++; 24 | } 25 | 26 | return answer; 27 | } 28 | -------------------------------------------------------------------------------- /archive/Coding Practice/No7.txt: -------------------------------------------------------------------------------- 1 | H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 2 | 3 | 어떤 과학자가 발표한 논문 n편 중, h번 이상 인용된 논문이 h편 이상이고 나머지 논문이 h번 이하 인용되었다면 h의 최댓값이 이 과학자의 H-Index입니다. 4 | 5 | 어떤 과학자가 발표한 논문의 인용 횟수를 담은 배열 citations가 매개변수로 주어질 때, 이 과학자의 H-Index를 return 하도록 solution 함수를 작성해주세요. 6 | 7 | 제한사항 8 | 과학자가 발표한 논문의 수는 1편 이상 1,000편 이하입니다. 9 | 논문별 인용 횟수는 0회 이상 10,000회 이하입니다. 10 | 입출력 예 11 | citations return 12 | [3, 0, 6, 1, 5] 3 13 | 입출력 예 설명 14 | 이 과학자가 발표한 논문의 수는 5편이고, 그중 3편의 논문은 3회 이상 인용되었습니다. 그리고 나머지 2편의 논문은 3회 이하 인용되었기 때문에 이 과학자의 H-Index는 3입니다. 15 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.02.09 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | int arr[] = {0, 5, 0, 3, -1}; 7 | 8 | int interval = 0; 9 | for (int i = 0; i + interval < (sizeof(arr) / sizeof(*arr)); i++) { 10 | if ((i + interval) >= (sizeof(arr) / sizeof(*arr)) - 1) interval--; 11 | if (arr[i] == 0) { 12 | ++interval; 13 | arr[i] = arr[i + interval]; 14 | arr[i + interval] = 0; 15 | } 16 | else { 17 | arr[i] = arr[i + interval]; 18 | } 19 | } 20 | 21 | 22 | for (int i = 0; i < (sizeof(arr) / sizeof(*arr)); i++) 23 | cout << arr[i] << " "; 24 | } 25 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/biggestsquare.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int squaresearch(vector> input, int startpoint) { 6 | int size; 7 | 8 | 9 | return size; 10 | } 11 | 12 | int solution(vector> board) { 13 | int answer = 1234; 14 | int vertical_length = board.size(); 15 | int horizontal_length = board[0].size(); 16 | 17 | for(int i = 0; i < vertical_length; i++) { 18 | board 19 | } 20 | 21 | // [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. 22 | cout << << endl; 23 | 24 | return answer; 25 | } -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_가장큰정사각형찾기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int solution(vector> board) 6 | { 7 | int answer = 0; 8 | 9 | if(board.size()<2 || board[0].size()<2){ 10 | return 1; 11 | } 12 | 13 | for(int i=1;i 2 -> 4 -> 3 -> 0 -> 1 16 | 17 | 18 | 19 | Input: [1, 4, 5, 0, 3, 2] 20 | 21 | Output: False 22 | 23 | // 1 -> 4 -> 3 -> 0 -> 1 24 | 25 | // arr[2], arr[5]를 들리지 않았습니다. 26 | 27 | 28 | 29 | Input: [1, 2, 2, 0] 30 | 31 | Output: False 32 | 33 | // 1 -> 2 -> 2 -> 2 -> … 34 | 35 | // arr[0]로 돌아오지 못합니다. 36 | 37 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/samsungexplain/easy2048.md: -------------------------------------------------------------------------------- 1 | 1. dfs 중복순열로 회전 방향을 정한다. 회전할 때는 move 함수를 실행해서 바로 이동한다 2 | 3 | temp_a에는 회전하기 전의 보드 상태가 저장되있고 회전하지 않으면 temp_a를 불러와서 지도를 초기화한다 4 | 5 | 2. move 함수는 입력 받은 방향에 따라서 한번에 이동한다. dir = 0~3은 각각 상하좌우 방향을 의미한다 6 | 7 | 3. 위로 이동할 경우 이동할 맨 끝 idx를 0으로 설정한다 8 | 9 | 4. 블럭이 있으면 조건대로 구현한다 10 | 11 | a[idx][j]가 0이면 빈칸이기 이므로 옮기기만 한다. 나중에 합칠 수 있는지 확인해야 하기 때문에 idx는 변하지 않는다 12 | 13 | a[idx][j]가 같은 값이면 합쳐서 두배를 만들고, 한 번 합친 블럭은 더 합칠 수 없으므로 idx를 증가시킨다 14 | 15 | 블럭이 있는데 다른 값이면 그 위에 쌓여야 하기 때문에 idx를 먼저 증가시키고 블럭을 옮긴다 16 | 17 | 다른 방향도 위와 같이 구현하면 된다 18 | 19 | 5. 5번 이동했으면 최대값을 갱신한다. -------------------------------------------------------------------------------- /archive/SeHyeon/20.02.02 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define DO_NOT_FIND NULL 4 | 5 | int main() { 6 | int arr[] = { 3, 3, 3 }; 7 | int firstBig, secondBig = DO_NOT_FIND; 8 | firstBig = arr[0]; 9 | 10 | for (int i = 1; i < (sizeof(arr) / sizeof(*arr)); i++) { 11 | if (arr[i] > firstBig) { 12 | secondBig = firstBig; 13 | firstBig = arr[i]; 14 | } 15 | else if (arr[i] < firstBig) { 16 | if (arr[i] > secondBig) 17 | secondBig = arr[i]; 18 | } 19 | } 20 | 21 | if (secondBig == DO_NOT_FIND) cout << "Does not exist" << endl; 22 | else cout << secondBig << endl; 23 | } 24 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.09.07 Coding Practice No.11(Success).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | string solution(vector participant, vector completion) { 7 | unordered_multiset us; 8 | for (vector::iterator iter = participant.begin(); iter != participant.end(); iter++) 9 | us.insert(*iter); 10 | for (vector::iterator iter = completion.begin(); iter != completion.end(); iter++) 11 | us.erase(us.find(*iter)); 12 | return *us.begin(); 13 | } 14 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/stringsort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(vector strings, int n) { 7 | 8 | for (int i = 0; i < strings.size(); i++) { 9 | for (int j = i+1; j <= strings.size()-1; j++) { 10 | if (strings[i][n]>strings[j][n]) { 11 | strings[i].swap(strings[j]); 12 | } 13 | else if (strings[i][n] == strings[j][n] && strings[i]>strings[j]) { 14 | strings[i].swap(strings[j]); 15 | } 16 | } 17 | } 18 | return strings; 19 | } 20 | -------------------------------------------------------------------------------- /archive/ayt/매프200608_practice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 100 3 | using namespace std; 4 | 5 | int tmp[SIZE] = { 0, }; 6 | int result; 7 | 8 | void Gcd(int inp[],int n) { 9 | for (int i = 0; i < n; i++) { 10 | for (int j = 1; j <= inp[i]; j++) { 11 | if (inp[i] % j == 0) 12 | ++tmp[j]; 13 | } 14 | } 15 | 16 | for (int i = 0; i < SIZE; i++) { 17 | if (tmp[i] == n) 18 | result = i; 19 | } 20 | cout << "ouput : " << result; 21 | } 22 | 23 | int main() { 24 | int input[] = { 2,4,6,8 }; 25 | int size = sizeof(input) / sizeof(int); 26 | 27 | Gcd(input, size); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_주식가격.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(vector prices) { 7 | vector answer; 8 | int n; 9 | 10 | for(int i=0;i 2 | using namespace std; 3 | 4 | char result[100]; 5 | char temp[10]; 6 | 7 | void Reverse(char temp[100]) { 8 | int t1 = 0, t2 = 0; 9 | for (int i = 0; i < 100; i++) { 10 | if (temp[i] == ' ') { 11 | for (int j = i - 1; j >= t2; j--) { 12 | result[t1] = temp[j]; 13 | t1++; 14 | } 15 | t2 = ++t1; 16 | } 17 | } 18 | } 19 | 20 | int main() 21 | { 22 | char inp[100] = "abc 123 apple "; 23 | cout << "Input: " << inp << endl; 24 | Reverse(inp); 25 | cout << "Output: "; 26 | for (int i = 0; i < 100; i++) 27 | cout << result[i]; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/2020_firsthalf/DP200504.cpp: -------------------------------------------------------------------------------- 1 | // O(n log n)시간 복잡도를 가진 정수 배열 정렬 알고리즘을 구현하시오. 2 | 3 | 4 | 5 | // Implement an O(n log n) time complexity sorting algorithm. 6 | 7 | 8 | 9 | // 예제) 10 | 11 | // Input: [3, 1, 5, 6] 12 | 13 | // Output: [1, 3, 5, 6] 14 | 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | 20 | int main(){ 21 | vector array; 22 | int a; 23 | 24 | for (int i = 0; i < 4; i++) 25 | { 26 | cin >> a; 27 | array.push_back(a); 28 | } 29 | 30 | sort(array.begin(), array.end()); 31 | 32 | } -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Hash/Hash-undercover.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(vector> clothes) { 8 | int answer = 1; 9 | map clothesboard; 10 | string temp; 11 | for(int i = 0; i < clothes.size(); i++) { 12 | temp = clothes[i][1]; 13 | clothesboard[temp] += 1; 14 | } 15 | map::iterator it; 16 | for(it = clothesboard.begin(); it != clothesboard.end(); it++) { 17 | answer = answer * (it->second + 1); 18 | } 19 | answer -= 1; 20 | return answer; 21 | } -------------------------------------------------------------------------------- /archive/YoungSeo/땅따먹기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int findMax(vector v, int y){ 8 | int x = 0; 9 | for(int i = 0; i < 4; i++) 10 | if(i != y) 11 | x = max(x, v[i]); 12 | return x; 13 | } 14 | 15 | int solution(vector > land) 16 | { 17 | int answer = 0; 18 | for(int i = 1; i < land.size(); i++){ 19 | for(int j = 0; j < 4; j++){ 20 | land[i][j] += findMax(land[i - 1], j); 21 | answer = max(answer, land[i][j]); 22 | } 23 | } 24 | return answer; 25 | } 26 | -------------------------------------------------------------------------------- /archive/ayt/매프200106.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool palindrome(char x[], int size) { 5 | int i = 0; 6 | while (true) { 7 | if ((x[i] == x[size - 1 - i])) return true; 8 | else return false; 9 | } 10 | } 11 | 12 | int main() 13 | { 14 | char input[100] = { '\0', }; 15 | int size = 0; 16 | 17 | cout << "Input: "; 18 | cin >> input; 19 | for (int i = 0; i < 100; i++) { 20 | if (input[i] != '\0') size++; 21 | } 22 | cout << size << endl; 23 | 24 | cout << "Oupit: "; 25 | if (palindrome(input, size)) cout << "true" << endl; 26 | else cout << "false" << endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /archive/ayt/매프200427.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void check(int inp[], int size) { 5 | int i = 0; 6 | int tmp = 0; 7 | 8 | while (1) { 9 | cout << inp[i] << " "; 10 | i = inp[i]; 11 | tmp++; 12 | if (i == 0) { 13 | cout << inp[i]; 14 | break; 15 | } 16 | else if (tmp > size) 17 | break; 18 | } 19 | cout << endl; 20 | 21 | if (tmp == size && i == 0) 22 | cout << "True"; 23 | else 24 | cout << "False"; 25 | } 26 | 27 | int main() { 28 | int input[] = { 3,2,0,4,1 }; 29 | int size = sizeof(input) / sizeof(int); 30 | 31 | check(input, size); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/matrixmultiply.py: -------------------------------------------------------------------------------- 1 | def solution(arr1, arr2): 2 | answer = [] 3 | # middleSet = [] 4 | 5 | # for i in range(len(arr2[0])) : 6 | # for j in range(len(arr1)) : 7 | # middleSet.append(0) 8 | # answer.append(middleSet) 9 | # middleSet = [] 10 | 11 | answer = [[0 for _ in range(len(arr2[0]))] for _ in range(len(arr1))] 12 | 13 | for i in range(len(arr1)): 14 | for j in range(len(arr2[0])): 15 | for k in range(len(arr1[0])): 16 | answer[i][j] += (arr1[i][k] * arr2[k][j]) 17 | 18 | return answer 19 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.05.11 Coding Practice No.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | string solution(int n) { 6 | string answer = ""; 7 | 8 | for (int i = 0; i < n; i++) 9 | if (i % 2) answer += "박"; 10 | else answer += "수"; 11 | 12 | return answer; 13 | } 14 | 15 | int main() { 16 | cout << solution(4) << endl; 17 | } 18 | 19 | //#1 20 | //for (int i = 0; i < n; i++) 21 | // i & 1 ? answer += "박" : answer += "수"; 22 | 23 | //#2 24 | //for (int i = 0; i < n / 2; i++) { 25 | // answer.append("수박"); 26 | //} 27 | //if (n % 2 == 1) 28 | //answer.append("수"); 29 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.01.09 Coding Practice No.32.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector solution(int n, vector words) { 7 | set table; 8 | for (int i = 0, count = 1; i < words.size(); i++, count++) { 9 | if (table.find(words[i]) != table.end()) return { count % n == 0 ? n : count % n, (int)ceil((double)count / n) }; 10 | if (i != 0 && words[i - 1][words[i - 1].size() - 1] != words[i][0]) return { count % n == 0 ? n : count % n, (int)ceil((double)count / n) }; 11 | table.insert(words[i]); 12 | } 13 | return { 0, 0 }; 14 | } 15 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/2020_firsthalf/DP200202.cpp: -------------------------------------------------------------------------------- 1 | // 정수 배열(int array)이 주어지면 두번째로 큰 값을 프린트하시오. 2 | 3 | 4 | 5 | // Given an integer array, find the second largest element. 6 | 7 | 8 | 9 | // 예제) 10 | 11 | // Input: [10, 5, 4, 3, -1] 12 | 13 | // Output: 5 14 | 15 | 16 | 17 | // Input: [3, 3, 3] 18 | 19 | // Output: Does not exist. 20 | 21 | #include 22 | using namespace std; 23 | 24 | int main() 25 | { 26 | int *input = new int[5]; 27 | 28 | cout << "Input : ["; 29 | 30 | for(auto n : input[]) 31 | { 32 | cin >> input[n]; 33 | } 34 | 35 | delete input[]; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Sorting-findingK.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] solution(int[] array, int[][] commands) { 3 | int[] answer = {}; 4 | int[] temp = {}; 5 | int startpoint, endpoint, target; 6 | for(int i = 0; i < commands.length; i++) 7 | { 8 | startpoint = commands[i][0]; 9 | endpoint = commands[i][1]; 10 | target = commands[i][2]; 11 | 12 | for(int j = 0; j < endpoint - startpoint; j++) 13 | { 14 | temp[j] = array[j + startpoint]; 15 | } 16 | } 17 | return answer; 18 | } 19 | } -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_전화번호목록.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool solution(vector phone_book) { 8 | bool answer = true; 9 | int tmp = 0; 10 | 11 | sort(phone_book.begin(), phone_book.end()); 12 | 13 | for(int i=1;i 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | long long first = 0, second = 1, answer = 0; //first is f(x)'s answer 7 | int limit; cin >> limit; 8 | 9 | vector saveFB; 10 | 11 | while(true){ 12 | long long tmp = second; 13 | second += first; 14 | first = tmp; 15 | 16 | if (first > limit) break; 17 | saveFB.push_back(first); 18 | } 19 | 20 | for (vector::iterator iter = saveFB.begin(); iter != saveFB.end(); iter++) { 21 | if (!(*iter % 2)) answer += *iter; 22 | //cout << *iter << " "; 23 | } 24 | cout << answer << endl; 25 | } 26 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.06.22 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int input[] = { 1, 2, 3, 8 }; 5 | int arr_size = sizeof(input) / sizeof(input[0]); 6 | int identify = 0; 7 | 8 | bool ok = true; 9 | 10 | void id(int* input2, int key) { 11 | int tmp; 12 | for (int i = 0; i < arr_size; i++) { 13 | tmp = input[i]; 14 | key -= tmp; 15 | input[i] = 0; 16 | id(input, key); 17 | input[i] = tmp; 18 | } 19 | identify = key; 20 | } 21 | 22 | 23 | int solution(int *input) { 24 | int i; 25 | for (i = 1; identify != 0; i++) id(input, i); 26 | return i; 27 | } 28 | 29 | int main() { 30 | cout << solution(input) << endl; 31 | } 32 | -------------------------------------------------------------------------------- /archive/ayt/백준_헤이카카오.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solution(int a, float d, float k) { 8 | float sum = a * d; 9 | vector win; 10 | 11 | while (d <= 1) { 12 | win.push_back(d); 13 | d = d + d * k; 14 | } 15 | win.push_back(1); 16 | 17 | float tmp = 1; 18 | for (int i = 1; i < win.size(); i++) { 19 | tmp *= (1 - win[i-1]); 20 | sum += a * (i + 1) * tmp * win[i]; 21 | } 22 | 23 | printf("%.7f", sum); 24 | } 25 | 26 | int main() { 27 | int a, d, k; 28 | cin >> a >> d >> k; 29 | 30 | solution(a, (float)d/100, (float)k/100); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /archive/SongChiHoon/OnBook/PICNIC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | bool friendship[10][10] = {}; 6 | int countingarray; 7 | 8 | int main() 9 | { 10 | int casenum, studentnum, friendnum, temp = 0; 11 | 12 | cout << "케이스 수 입력 : "; cin >> casenum; 13 | 14 | while (casenum != 0) 15 | { 16 | cout << "학생 수와 친구 수 입력 : "; cin >> studentnum; cin >> friendnum; 17 | cout << endl << "친구 쌍 입력하기" << endl; 18 | 19 | vector friendinfo; 20 | 21 | for (int i = 0; i < friendnum * 2; i++) 22 | cin >> temp; 23 | friendinfo.push_back(temp); 24 | 25 | 26 | casenum--; 27 | } 28 | 29 | return 0; 30 | 31 | } -------------------------------------------------------------------------------- /archive/MoonSeong/210418DFS.py: -------------------------------------------------------------------------------- 1 | def dfs(x, computers, remainder): 2 | contained = [] 3 | for i in range(len(computers[x])): 4 | if computers[x][i] == 1 and i in remainder: 5 | contained.append(i) 6 | for _ in contained: 7 | remainder.remove(_) 8 | for c in contained: 9 | dfs(c, computers, remainder) 10 | 11 | def solution(n, computers): 12 | answer = 0 13 | 14 | remainder = [] 15 | for i in range(n): 16 | remainder.append(i) 17 | #main routine 18 | while len(remainder) != 0: 19 | dfs(remainder[0], computers, remainder) 20 | answer += 1 21 | 22 | return answer 23 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.09.07 Coding Practice No.11(Not Success).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | string solution(vector participant, vector completion) { 7 | unordered_multiset us; 8 | for (vector::iterator iter = completion.begin(); iter != completion.end(); iter++) 9 | us.insert(*iter); 10 | for (vector::iterator iter = participant.begin(); iter != participant.end(); iter++) { 11 | unordered_multiset::iterator siter = us.find(*iter); 12 | if (siter == us.end()) return *iter; 13 | } 14 | return ""; 15 | } 16 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_124나라의숫자.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | string solution(int n) { 8 | string answer = ""; 9 | int r; 10 | 11 | while (n > 0) { 12 | r = n % 3; 13 | if (r == 0) { 14 | answer.push_back('4'); 15 | n = n/3 - 1; 16 | } 17 | else if (r == 1) { 18 | answer.push_back('1'); 19 | n /= 3; 20 | } 21 | else { 22 | answer.push_back('2'); 23 | n /= 3; 24 | } 25 | } 26 | 27 | reverse(answer.begin(), answer.end()); 28 | 29 | return answer; 30 | } 31 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_올바른괄호.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. 7 | bool solution(string s) { 8 | int cnt = 0; 9 | 10 | if(s[0] == ')') return false; 11 | else if(s[s.size()-1] == '(') return false; 12 | 13 | 14 | for(int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int sum1, sum2; 7 | int findMiss(int inp[],int n) { 8 | for (int i = 0; i < n; ++i) 9 | sum1 += inp[i]; 10 | 11 | srand((unsigned int)time(NULL)); 12 | inp[rand() % n] = NULL; 13 | 14 | for (int i = 0; i < n; ++i) 15 | sum2 += inp[i]; 16 | 17 | return sum1 - sum2; 18 | } 19 | 20 | int main() { 21 | int input[100]; 22 | int size = sizeof(input) / sizeof(int); 23 | 24 | for (int i = 0; i < 100; ++i) 25 | input[i] = i + 1; 26 | 27 | cout << findMiss(input, size); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /archive/Coding Practice/No20.txt: -------------------------------------------------------------------------------- 1 | 가로 길이가 Wcm, 세로 길이가 Hcm인 직사각형 종이가 있습니다. 종이에는 가로, 세로 방향과 평행하게 격자 형태로 선이 그어져 있으며, 모든 격자칸은 1cm x 1cm 크기입니다. 이 종이를 격자 선을 따라 1cm × 1cm의 정사각형으로 잘라 사용할 예정이었는데, 누군가가 이 종이를 대각선 꼭지점 2개를 잇는 방향으로 잘라 놓았습니다. 그러므로 현재 직사각형 종이는 크기가 같은 직각삼각형 2개로 나누어진 상태입니다. 새로운 종이를 구할 수 없는 상태이기 때문에, 이 종이에서 원래 종이의 가로, 세로 방향과 평행하게 1cm × 1cm로 잘라 사용할 수 있는 만큼만 사용하기로 하였습니다. 2 | 가로의 길이 W와 세로의 길이 H가 주어질 때, 사용할 수 있는 정사각형의 개수를 구하는 solution 함수를 완성해 주세요. 3 | 4 | 제한사항 5 | W, H : 1억 이하의 자연수 6 | 입출력 예 7 | W H result 8 | 8 12 80 9 | 입출력 예 설명 10 | 입출력 예 #1 11 | 가로가 8, 세로가 12인 직사각형을 대각선 방향으로 자르면 총 16개 정사각형을 사용할 수 없게 됩니다. 원래 직사각형에서는 96개의 정사각형을 만들 수 있었으므로, 96 - 16 = 80 을 반환합니다. 12 | 13 | 572957326.92.png 14 | -------------------------------------------------------------------------------- /archive/Coding Practice/No68.txt(BAEKJOON): -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/21734 2 | 3 | SMUPC의 등장 성공출처 4 | 시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율 5 | 1 초 (추가 시간 없음) 1024 MB 617 432 400 78.125% 6 | 문제 7 | 2021년 5월 8일 SMUPC 대회의 첫 개최에 신이 난 화은이는 SMUPC를 기념하기 위해 "SMUPC"를 예술적으로 출력하는 프로그램을 작성하고자 했다. 화은이는 각 알파벳에 해당하는 아스키코드 값을 10진법으로 나타내었을 때, 각 자릿수의 합만큼 출력하도록 하는 프로그램을 만들고자 한다. 하지만 화은이는 지금 문제를 출제해야 해서 정신이 없다. 문제 출제로 정신이 없는 화은이를 위해 화은이가 만들고자 하는 프로그램을 대신 만들어 보자. 8 | 9 | 입력 10 | 첫 줄에 알파벳 소문자로만 이루어진 단어 가 주어진다. 이때, 입력되는 의 길이는 을 넘지 않는다. 11 | 12 | 출력 13 | 단어 의 각 문자에 대한 프로그램의 출력값을 각 줄별로 출력한다. 14 | 15 | 예제 입력 1 16 | smupc 17 | 예제 출력 1 18 | sssssss 19 | mmmmmmmmmm 20 | uuuuuuuuu 21 | pppp 22 | cccccccccccccccccc 23 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-16 waveBarJim(Full Search).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string e, digits; 5 | int n, m; 6 | 7 | string price; 8 | //bool taken[15]; 전역변수로 놓으면 정적 바인딩이라 모든 재귀 호출 함수 쪽에서 동일한 배열을 사용하지만 9 | // 매개변수로 배열을 넘겨 줄 시 동적 바인딩이므로 재귀 호출 마다 새로운 taken 배열이 생성 되기 때문에 매개변수로 넘겨줌 10 | 11 | void generate(string price, bool taken[15]) { 12 | if (price.size() == n) { 13 | if (price < e) 14 | cout << price << endl; 15 | return; 16 | } 17 | for(int i = 0; i < n; i++) 18 | if (!taken[i] && (i == 0 || digits[i - 1] != digits[i] || taken[i - 1])) { 19 | taken[i] = true; 20 | generate(price + digits[i], taken); 21 | taken[i] = false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/rightbracket.py: -------------------------------------------------------------------------------- 1 | def solution(s): 2 | answer = True 3 | bracketlist = [] 4 | for bracket in s: 5 | if bracket == "(": 6 | bracketlist.append(bracket) 7 | continue 8 | if bracket == ")": 9 | if len(bracketlist) == 0: 10 | answer = False 11 | continue 12 | else: 13 | bracketlist.pop() 14 | continue 15 | if len(bracketlist) != 0: 16 | answer = False 17 | if answer == True: 18 | return True 19 | else: 20 | return False 21 | 22 | print('Hello Python') 23 | 24 | print(solution("(())")) -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Hash/Hash-unfinishedrunner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | string solution(vector participant, vector completion) { 8 | string answer = ""; 9 | map hashmap; 10 | for (int i = 0; i < participant.size(); i++) { 11 | hashmap[participant[i]] += 1; 12 | } 13 | for (int i = 0; i < completion.size(); i++) { 14 | hashmap[completion[i]] -= 1; 15 | } 16 | for (int i = 0; i < participant.size(); ++i) { 17 | if (hashmap[participant[i]] != 0) { 18 | answer = participant[i]; 19 | } 20 | } 21 | return answer; 22 | } -------------------------------------------------------------------------------- /archive/ayt/매프200518.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void shift(int inp[], int k, int size) { 6 | int tmp[100]; 7 | 8 | if (k > size) k %= size; 9 | 10 | for (int i = 0; i < k; i++) { 11 | tmp[i] = inp[i]; 12 | inp[i] = 123456789; 13 | } 14 | 15 | sort(inp, inp + size); 16 | 17 | int j = k; 18 | for (int i = 0; i < k; i++) { 19 | inp[size - j] = tmp[i]; 20 | j--; 21 | } 22 | 23 | for (int i = 0; i < size; i++) 24 | cout << inp[i] << " "; 25 | } 26 | 27 | int main() { 28 | int input[] = { 1,2,3,4,5 }; 29 | int k = 2; 30 | int size = sizeof(input) / sizeof(int); 31 | 32 | shift(input, k, size); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_입국심사.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | long long solution(int n, vector times) { 7 | long long maxTimes = 0; 8 | 9 | for (auto elem : times) 10 | if(elem>maxTimes) maxTimes = elem; 11 | 12 | long long start = 1; 13 | long long end = maxTimes * n; 14 | long long i; 15 | 16 | while(start<=end) { 17 | long long mid = (start + end) / 2; 18 | i = 0; 19 | 20 | for(auto elem : times) { 21 | i += mid / elem; 22 | if(i>=n) end = mid - 1; 23 | } 24 | if(i 2 | #include 3 | using namespace std; 4 | 5 | int findGCD(vector& input) { 6 | int min = 987654321; 7 | bool ok = true; 8 | 9 | for (int i = 0; i < input.size(); i++) 10 | if (min > input[i]) min = input[i]; 11 | for (int i = 0; i < input.size(); i++) 12 | if (input[i] % min) { 13 | ok = false; 14 | break; 15 | } 16 | 17 | if (ok) return min; 18 | else return 1; 19 | } 20 | 21 | int main() { 22 | vector input; 23 | int arr[] = {2, 4, 6, 8, 9}; 24 | 25 | for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) 26 | input.push_back(arr[i]); 27 | 28 | int gcd = findGCD(input); 29 | cout << gcd << endl; 30 | } 31 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.06.27 Coding Practice No.62.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/43238 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | long long solution(int n, vector times) { 9 | long long answer = 0; 10 | long long start = 1; 11 | long long end = *max_element(times.begin(), times.end()) * n; 12 | 13 | while (start <= end) { 14 | long long mid = (start + end) / 2; 15 | int count = 0; 16 | for (int i = 0; i < times.size(); i++) { 17 | count += (int)(mid / times[i]); 18 | if (count > n) 19 | end = mid - 1; 20 | if (count < n) 21 | start = mid + 1; 22 | } 23 | } 24 | return end; 25 | } 26 | -------------------------------------------------------------------------------- /archive/Simple matter/20.04.05 matter: -------------------------------------------------------------------------------- 1 | 0과 1로 만들어진 2D 정수 배열이 있습니다. 0은 장애물이고 1은 도로일때, 두 좌표가 주어지면, 첫번째 좌표에서 두번째 좌표까지 가장 가까운 거리를 구하시오. 두 좌표는 모두 도로에서 시작되고 좌, 우, 아래, 위로 움직이며 대각선으로는 움직일 수 없습니다. 만약 갈 수 없다면 -1을 리턴하시오. 2 | 3 | 4 | 5 | Given a 2D array with 0s and 1s, 0 represents an obstacle and 1 represents a road. Find the closest distance between two given points. You must only move up down right left. You cannot move through an obstacle. 6 | 7 | 8 | 9 | 예제) 10 | 11 | Input: 12 | 13 | {{1, 0, 0, 1, 1, 0}, 14 | 15 | {1, 0, 0, 1, 0, 0}, 16 | 17 | {1, 1, 1, 1, 0, 0}, 18 | 19 | {1, 0, 0, 0, 0, 1}, 20 | 21 | {1, 1, 1, 1, 1, 1}} 22 | 23 | Start: (0, 0) 24 | 25 | Finish: (0, 4) 26 | 27 | 28 | 29 | Output: 8 30 | -------------------------------------------------------------------------------- /archive/ayt/매프200504.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int inp[] = { 3,1,5,6 }; 5 | 6 | void quick(int x, int y) { 7 | if (x >= y) return; 8 | int p = inp[(x + y) / 2]; 9 | int left = x; 10 | int right = y; 11 | 12 | while (left <= right) { 13 | while (inp[left] < p) left++; 14 | while (inp[right] > p) right--; 15 | if (left <= right) { 16 | swap(inp[left], inp[right]); 17 | left++, right--; 18 | } 19 | } 20 | quick(x, right); 21 | quick(left, y); 22 | } 23 | 24 | void display(int inp[]) { 25 | for (int i = 0; i < 4; i++) { 26 | cout << inp[i] << " "; 27 | } 28 | } 29 | 30 | int main() { 31 | quick(0, 4); 32 | display(inp); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /archive/GyuMin/전화번호.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/42577 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool solution(vector phone_book) 9 | { 10 | bool answer = true; 11 | 12 | sort(phone_book.begin(), phone_book.end()); 13 | 14 | for (int i = 0; i < phone_book.size(); i++) 15 | { 16 | for (int j = i + 1; j < phone_book.size(); j++) 17 | if (phone_book[i] == phone_book[j].substr(0, phone_book[i].size())) 18 | { 19 | answer = false; 20 | 21 | return answer; 22 | } 23 | } 24 | 25 | return answer; 26 | } 27 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.01.26 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string reverseString(string s) 5 | { 6 | string reversed = ""; 7 | 8 | int start = 0; 9 | for (int i = 0; i < s.length(); i++) { 10 | if (s[i] == ' ') { 11 | string sub = s.substr(start, i - start); 12 | reverse(sub.begin(), sub.end()); 13 | reversed += sub + " "; 14 | start = i + 1; 15 | } 16 | else if (i == s.length() - 1) { 17 | string sub = s.substr(start, i - start + 1); 18 | reverse(sub.begin(), sub.end()); 19 | reversed += sub; 20 | } 21 | } 22 | return reversed; 23 | } 24 | 25 | int main() { 26 | string s = "abc apple banana"; 27 | 28 | cout << reverseString(s) << endl; 29 | } 30 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-1 lis4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int n; 4 | int cache[101], S[100], choices[101]; 5 | 6 | int lis4(int start) { 7 | int& ret = cache[start + 1]; 8 | if (ret != -1) return ret; 9 | ret = 1; 10 | int bestNext = -1; 11 | for(int next = start + 1; next < n; ++next) 12 | if (start == -1 || S[start] < S[next]) { 13 | int cand = lis4(next) + 1; 14 | if (cand > ret) { 15 | ret = cand; 16 | bestNext = next; 17 | } 18 | } 19 | choices[start + 1] = bestNext; 20 | return ret; 21 | } 22 | 23 | void reconstruct(int start, vector& seq) { 24 | if (start != -1) seq.push_back(S[start]); 25 | int next = choices[start + 1]; 26 | if (next != -1) reconstruct(next, seq); 27 | } 28 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.05.11 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //int input[] = { 1, 2, 3, 7, 10 }; 5 | //int input[] = { -5, -3, 0, 1}; 6 | int input[] = { 1, 4, 5, 6, 8, 9 }; 7 | 8 | bool binarySerch(int target, int start = 0, int end = sizeof(input) / sizeof(input[0]), int* arr = input) { 9 | int mid = (start + end) / 2; 10 | 11 | if (start > end) return false; 12 | else { 13 | if (arr[mid] == target) return true; 14 | else { 15 | if (arr[mid] < target) binarySerch(target, mid + 1, end); 16 | else if (arr[mid] > target) binarySerch(target, start, mid - 1); 17 | } 18 | } 19 | } 20 | 21 | int main() { 22 | binarySerch(9) == 1 ? cout << "True\n" : cout << "Flase\n"; 23 | } 24 | -------------------------------------------------------------------------------- /archive/ayt/매프200120.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int result[11] = { 0, }; 5 | 6 | void interval(int n[3][2]) { 7 | for (int i = 0; i < 3; i++) 8 | for (int j = n[i][0]; j <= n[i][1]; j++) 9 | result[j] = 1; 10 | for (int i = 0; i < 10; i++) { 11 | if (result[i] == 1 && ((result[i - 1] != 1) || (result[i + 1] != 1))) 12 | cout << i << " "; 13 | if (result[i + 1] == 0) 14 | cout << endl; 15 | } 16 | } 17 | 18 | int main() 19 | { 20 | int n[3][2] = { 0, }; 21 | cout << "Input " << endl; 22 | for (int i = 0; i < 3; i++) 23 | cin >> n[i][0] >> n[i][1]; //2 4 Enter 1 5 Enter 7 9 Enter 24 | cout << "Ouput " << endl; 25 | interval(n); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /archive/ayt/백준_연속합.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int solution(int n, vector array) { 7 | vector dp = array; 8 | int sum = dp[0]; 9 | 10 | for (int i = 1; i < n; i++) { 11 | if (sum + array[i] >= array[i]) { 12 | sum += array[i]; 13 | dp[i] = sum; 14 | } 15 | else { 16 | sum = dp[i]; 17 | } 18 | } 19 | 20 | int max = -1001; 21 | 22 | for (auto elem : dp) 23 | if (elem > max) max = elem; 24 | 25 | return max; 26 | } 27 | 28 | int main() { 29 | int n; 30 | cin >> n; 31 | 32 | vector array(n); 33 | 34 | for (int i = 0; i < n; i++) { 35 | cin >> array[i]; 36 | } 37 | 38 | cout << solution(n, array) << endl; 39 | } 40 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.01.20 matter (my method).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define SIZE 20 4 | 5 | int main() { 6 | int range[SIZE] = { 0, }; 7 | while (true) { 8 | int start, end; cin >> start >> end; 9 | if (start == -1 || end == -1) break; 10 | 11 | for (int i = start - 1; i < end; i++) { 12 | range[i] = 1; 13 | } 14 | } 15 | 16 | int st = 0, en = 0; 17 | bool con = false; 18 | for (int i = 0; i < SIZE; i++) { 19 | if (range[i] && !con) { 20 | st = i + 1; 21 | con = true; 22 | } 23 | if (!range[i] && con) { 24 | en = i; 25 | con = false; 26 | } 27 | 28 | if (st && en) { 29 | cout << st << " " << en << endl; 30 | st = en = 0; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.05.30 Coding Practice No.57.cpp(Brute Force - Time out): -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | long long fx(long long num) { 8 | bitset<64> stdBs = num; 9 | 10 | for (long long i = num + 1; ; i++) { 11 | bitset<64> cmpBs = i; 12 | bitset<64> diffBs = (stdBs ^ cmpBs); 13 | 14 | if (diffBs.count() <= 2 && diffBs.count() >= 1) 15 | return i; 16 | } 17 | } 18 | 19 | vector solution(vector numbers) { 20 | vector answer; 21 | 22 | for (auto fetch : numbers) 23 | answer.emplace_back(fx(fetch)); 24 | return answer; 25 | } 26 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/dynamicprogramming/Longjump.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | int numbers[2000]; 6 | 7 | long long recursive(int n) { 8 | if(n == 0) { 9 | return numbers[n] = 0; 10 | } 11 | if(n == 1) { 12 | return numbers[n] = 1; 13 | } 14 | if(n == 2) { 15 | return numbers[n] = 2; 16 | } 17 | if(numbers[n] != 0) { 18 | return numbers[n]; 19 | } 20 | return numbers[n] = (recursive(n-1) + recursive(n-2)) % 1234567; 21 | } 22 | 23 | long long solution(int n) { 24 | long long answer = 0; 25 | 26 | recursive(n); 27 | 28 | answer = numbers[n] % 1234567; 29 | return answer; 30 | } -------------------------------------------------------------------------------- /archive/YoungSeo/더맵게.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | int solution(vector scoville, int K) { 9 | int answer = 0; 10 | 11 | priority_queue,greater> temp; 12 | for(int i=0;i 1) { 16 | int first,second; 17 | 18 | first = temp.top(); 19 | temp.pop(); 20 | second = temp.top(); 21 | temp.pop(); 22 | temp.push(first + second * 2); 23 | answer++; 24 | } 25 | if (temp.top() < K) 26 | return -1; 27 | return answer; 28 | } 29 | -------------------------------------------------------------------------------- /archive/YoungSeo/소수만들기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | bool PrimeNum(int num){ 6 | if(num==0 || num==1) return false; 7 | for(int i=2; i nums) { 14 | int answer = 0; 15 | 16 | for(int i=0; i 2 | using namespace std; 3 | 4 | int smallInt(int inp[], int n) { 5 | int ck[100] = { 0, }; 6 | 7 | if (inp[0] != 1) 8 | return 1; 9 | if (inp[1] != 2) 10 | return 2; 11 | 12 | for (int i = 0; i < n; ++i) { 13 | ck[inp[i]] = 1; 14 | } 15 | for (int i = 0; i < n; ++i) { 16 | for (int j = i + 1; j < n; ++j) { 17 | ck[inp[i] + inp[j]] = 1; 18 | } 19 | } 20 | for (int i = 1; i < 100; ++i) { 21 | if (ck[i] == 0) { 22 | return i; 23 | break; 24 | } 25 | } 26 | } 27 | 28 | int main() { 29 | int input[] = { 1,2,3,6,10 }; 30 | int size = sizeof(input) / sizeof(int); 31 | 32 | cout << "output : " << smallInt(input, size); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.12.27 Coding Practice No.27(Compelete).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int solution(vector> land){ 6 | for (int i = 1; i < land.size(); i++) { 7 | int beforeMax = *max_element(land[i - 1].begin(), land[i - 1].end()); 8 | int beforeIndex = find(land[i - 1].begin(), land[i - 1].end(), beforeMax) - land[i - 1].begin(); 9 | for (int j = 0; j < 4; j++) 10 | if (j != beforeIndex) land[i][j] += beforeMax; 11 | else { 12 | land[i - 1][beforeIndex] = -1; 13 | land[i][j] += *max_element(land[i - 1].begin(), land[i - 1].end()); 14 | } 15 | } 16 | return *max_element(land[land.size() - 1].begin(), land[land.size() - 1].end()); 17 | } 18 | -------------------------------------------------------------------------------- /archive/ayt/백준_눈덩이굴리기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solution(int N, int M, vector a, int size, int pos, int t, int &result) { 8 | if (t > M) return; 9 | 10 | result = max(size, result); 11 | 12 | if (pos + 1 <= N) solution(N, M, a, size + a[pos + 1], pos + 1, t + 1, result); 13 | if (pos + 2 <= N) solution(N, M, a, size / 2 + a[pos + 2], pos + 2, t + 1, result); 14 | } 15 | 16 | int main() { 17 | int N, M, result = 0; 18 | cin >> N >> M; 19 | 20 | vector a(N + 1); 21 | 22 | a[0] = 0; 23 | 24 | for (int i = 1; i < N + 1; i++) 25 | cin >> a[i]; 26 | 27 | solution(N, M, a, 1, 0, 0, result); 28 | 29 | cout << result; 30 | } 31 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_행렬의곱샘.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | //14 7 | //32 33 8 | //41 33 9 | 10 | //232 543 11 | //424 241 12 | //314 311 13 | 14 | vector> solution(vector> arr1, vector> arr2) { 15 | vector> answer; 16 | 17 | for(int i=0;i a; 19 | for(int k=0;k 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string input; 10 | 11 | cin >> input; 12 | 13 | int n; 14 | 15 | cin >> n; 16 | 17 | string answer = ""; 18 | 19 | char letter, start; 20 | int movesize; 21 | 22 | for(int i = 0; i < input.length(); i++) 23 | { 24 | if(input[i] != ' ') 25 | { 26 | start = ('A' <= input[i] && input[i] <= 'Z')? 'A' : 'a'; 27 | letter = start + (input[i] + n - start)%26; 28 | } 29 | else 30 | letter = ' '; 31 | answer.push_back(letter); 32 | } 33 | } -------------------------------------------------------------------------------- /archive/SeHyeon/20.05.18 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int inputSize; 5 | 6 | void moveArray(int* input, int k) { 7 | int* tmp = new int[k]; 8 | for (int i = 0; i > k; 23 | 24 | inputSize = sizeof(input) / sizeof(input[0]); 25 | moveArray(input, k); 26 | 27 | for (int i = 0; i < inputSize; i++) 28 | cout << input[i] << " "; 29 | } 30 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/scoville.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(vector scoville, int K) { 9 | int answer = 0; 10 | 11 | priority_queue,greater> temp; 12 | for (int i=0;i1) { 17 | int first, second; 18 | answer++; 19 | first = temp.top(); temp.pop(); 20 | second = temp.top(); temp.pop(); 21 | temp.push(first + second * 2); 22 | } 23 | 24 | if (temp.top() < K) 25 | return -1; 26 | 27 | return answer; 28 | } -------------------------------------------------------------------------------- /archive/YoungSeo/카펫.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(int brown, int yellow) { 7 | vector answer; 8 | 9 | int width = brown + yellow; 10 | 11 | for(int a=3;a 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(int n, vector words) { 7 | vector answer = { 0,0 }; 8 | bool tf = false; 9 | 10 | for (int i = 1; i < words.size(); ++i) { 11 | for (int j = 0; j < i; ++j) { 12 | if (words[j] == words[i]) { 13 | tf = true; 14 | break; 15 | } 16 | } 17 | if (words[i - 1][words[i - 1].size() - 1] != words[i][0]) 18 | tf = true; 19 | 20 | if (tf) { 21 | answer[0] = i % n + 1; 22 | answer[1] = i / n + 1; 23 | break; 24 | } 25 | } 26 | 27 | return answer; 28 | } 29 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_정수삼각형.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define MAX 500 5 | 6 | using namespace std; 7 | 8 | vector> triangle; 9 | int cache[500][500]; 10 | 11 | int move(int a,int b){ 12 | if(a==triangle.size()-1) return triangle[a][b]; 13 | 14 | int& ret = cache[a][b]; 15 | if(ret != -1) return ret; 16 | return ret = max(move(a+1,b),move(a+1,b+1)) + triangle[a][b]; 17 | } 18 | 19 | int solution(vector> tmpTriangle) { 20 | triangle.assign(tmpTriangle.begin(), tmpTriangle.end()); 21 | 22 | for(int i=0;i 2 | #include 3 | #pragma warning(disable : 4996) 4 | 5 | using namespace std; 6 | 7 | int rolling(int size, int pos, vector& field) { 8 | size += field[pos]; 9 | return size; 10 | } 11 | 12 | int throwing(int size, int pos, vector& field) { 13 | size = (size / 2) + field[pos+1]; 14 | return size; 15 | } 16 | 17 | int main(void) { 18 | int n, m; 19 | scanf("%d %d", &n, &m); 20 | vector field(n); 21 | for (int i = 0; i < n; i++) 22 | scanf("%d", &field[i]); 23 | 24 | //start 25 | int rollExpectedVal; 26 | int throwExpectedVal; 27 | int size = 1; 28 | int pos = 0; 29 | int time = 1; 30 | while (time > 1 && ) 31 | } 32 | -------------------------------------------------------------------------------- /archive/Coding Practice/No22.txt: -------------------------------------------------------------------------------- 1 | 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 2 | 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 3 | 4 | 구조대 : 119 5 | 박준영 : 97 674 223 6 | 지영석 : 11 9552 4421 7 | 전화번호부에 적힌 전화번호를 담은 배열 phone_book 이 solution 함수의 매개변수로 주어질 때, 어떤 번호가 다른 번호의 접두어인 경우가 있으면 false를 그렇지 않으면 true를 return 하도록 solution 함수를 작성해주세요. 8 | 9 | 제한 사항 10 | phone_book의 길이는 1 이상 1,000,000 이하입니다. 11 | 각 전화번호의 길이는 1 이상 20 이하입니다. 12 | 입출력 예제 13 | phone_book return 14 | [119, 97674223, 1195524421] false 15 | [123,456,789] true 16 | [12,123,1235,567,88] false 17 | 입출력 예 설명 18 | 입출력 예 #1 19 | 앞에서 설명한 예와 같습니다. 20 | 21 | 입출력 예 #2 22 | 한 번호가 다른 번호의 접두사인 경우가 없으므로, 답은 true입니다. 23 | 24 | 입출력 예 #3 25 | 첫 번째 전화번호, “12”가 두 번째 전화번호 “123”의 접두사입니다. 따라서 답은 false입니다. 26 | 27 | -------------------------------------------------------------------------------- /archive/Coding Practice/No66.txt(BAEKJOON): -------------------------------------------------------------------------------- 1 | https://www.acmicpc.net/problem/1912 2 | 3 | 연속합 성공 4 | 시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율 5 | 1 초 (추가 시간 없음) 128 MB 84370 26973 18641 30.984% 6 | 문제 7 | n개의 정수로 이루어진 임의의 수열이 주어진다. 우리는 이 중 연속된 몇 개의 수를 선택해서 구할 수 있는 합 중 가장 큰 합을 구하려고 한다. 단, 수는 한 개 이상 선택해야 한다. 8 | 9 | 예를 들어서 10, -4, 3, 1, 5, 6, -35, 12, 21, -1 이라는 수열이 주어졌다고 하자. 여기서 정답은 12+21인 33이 정답이 된다. 10 | 11 | 입력 12 | 첫째 줄에 정수 n(1 ≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. 수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다. 13 | 14 | 출력 15 | 첫째 줄에 답을 출력한다. 16 | 17 | 예제 입력 1 18 | 10 19 | 10 -4 3 1 5 6 -35 12 21 -1 20 | 예제 출력 1 21 | 33 22 | 예제 입력 2 23 | 10 24 | 2 1 -4 3 4 -4 6 5 -5 1 25 | 예제 출력 2 26 | 14 27 | 예제 입력 3 28 | 5 29 | -1 -2 -3 -4 -5 30 | 예제 출력 3 31 | -1 32 | -------------------------------------------------------------------------------- /archive/Kimsh/mailproramming_0605.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | /* 8 | ���� �迭�� �־����� , �迭 ���� ��� ������ �ִ� �����(GCD)�� ���Ͻÿ�. 9 | �ٽð� ���⵵ ���� O(n)�� 10 | input: [3, 2, 1] 11 | output: 1 12 | 13 | input: [2, 4, 6, 8] 14 | output: 2 15 | */ 16 | array arr = {3,2,1}; 17 | void prime_factorization(int a);//���μ����� 18 | int main() { 19 | int min = INT16_MAX; 20 | for (int i = 0; i < 3; i++) { 21 | if (arr[min] > arr[i]) min = i ; 22 | } 23 | prime_factorization(min); 24 | return 0; 25 | } 26 | void prime_factorization(int a) { 27 | int find = true; 28 | for (int i = 0; i < 3; i++) { 29 | if (arr[i] % a != 0) { 30 | find = false; 31 | } 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /archive/MoonSeong/210301baseN_game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string decToN(int num, int n) { 7 | int q = num / n; 8 | int r = num % n; 9 | string strNum = "0123456789ABCDEF"; 10 | 11 | if (q == 0) 12 | return strNum.substr(r, 1); 13 | else 14 | return decToN(q, n) + strNum.substr(r, 1); 15 | } 16 | 17 | string solution(int n, int t, int m, int p) { 18 | string answer = ""; 19 | string gameStr = ""; 20 | 21 | int i = 0; 22 | while (gameStr.length() < m * (t-1) + p) 23 | gameStr += decToN(i++, n); 24 | 25 | for (int i = 0; i < t; i++) 26 | answer += gameStr[i * m + (p-1)]; 27 | 28 | return answer; 29 | } 30 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.07.03 Coding Practice No.63.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12985 2 | 3 | #include 4 | using namespace std; 5 | 6 | int nextStep(int n) { 7 | float tmp; 8 | 9 | tmp = (float)n / 2; 10 | tmp -= n / 2; 11 | if (tmp > 0) 12 | return (n / 2 + 1); 13 | return (n / 2); 14 | } 15 | 16 | int solution(int n, int a, int b) { 17 | int answer = 1; 18 | 19 | if (a > b) { 20 | int tmp = a; 21 | a = b; 22 | b = tmp; 23 | } 24 | while (true) { 25 | if (a % 2) 26 | if (a + 1 == b) 27 | break; 28 | a = nextStep(a); 29 | b = nextStep(b); 30 | answer++; 31 | } 32 | return answer; 33 | } 34 | -------------------------------------------------------------------------------- /archive/SongChiHoon/OnBook/OCR.cpp: -------------------------------------------------------------------------------- 1 | int n, m; 2 | 3 | int R[100]; 4 | 5 | double T[501][501]; 6 | 7 | double M[501][501]; 8 | int choice[102][502]; 9 | double cache[102][502]; 10 | 11 | double recognize(int segment, int previousMatch) { 12 | if(segment == n) return 0; 13 | double &ret = cache[segment][previousMatch]; 14 | if(ret != 1.0) return ret; 15 | ret = -1e200; 16 | int &choose = choice[segment][previousMatch]; 17 | 18 | for(int thisMatch = 0; thisMatch < m; ++thisMatch) { 19 | double cand = T[previousMatch][thisMatch] + M[thisMatch][R[segment]] + recognize(segment + 1, thisMatch); 20 | if(ret < cand) { 21 | ret = cand; 22 | choose = thisMatch; 23 | } 24 | } 25 | return ret; 26 | } -------------------------------------------------------------------------------- /archive/ayt/백준_창영이와버스.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solve(int N, int M, vector fee, vector> A) { 8 | int result = 0; 9 | 10 | for (int i = 1; i < fee.size(); i++) { 11 | int S = fee[i - 1]; 12 | int E = fee[i]; 13 | 14 | result += A[S - 1][E - 1]; 15 | } 16 | 17 | cout << result; 18 | } 19 | 20 | int main() { 21 | int N, M; 22 | cin >> N >> M; 23 | 24 | vector fee(M); 25 | vector> A(N, vector(N)); 26 | 27 | for (int i = 0; i < M; i++) 28 | cin >> fee[i]; 29 | 30 | for (int i = 0; i < N; i++) 31 | for (int j = 0; j < N; j++) 32 | cin >> A[i][j]; 33 | 34 | 35 | solve(N, M, fee, A); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /archive/MoonSeong/prefix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool isIn(string shortStr, string longStr) { 7 | if (shortStr == longStr.substr(0, shortStr.length())) return true; 8 | return false; 9 | } 10 | 11 | bool solution(vector phone_book) { 12 | for (int i = 0; i < phone_book.size() - 1; i++) 13 | for (int j = i + 1; j < phone_book.size(); j++) { 14 | if ((phone_book[i].length() >= phone_book[j].length()) && isIn(phone_book[j], phone_book[i])) 15 | return false; 16 | if ((phone_book[j].length() >= phone_book[i].length()) && isIn(phone_book[i], phone_book[j])) 17 | return false; 18 | } 19 | 20 | return true; 21 | } 22 | -------------------------------------------------------------------------------- /archive/SeHyeon/19.12.30 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void parentheses(int num, int open, int close, string s, vector& list) { 7 | if (close == num) { //completed 8 | list.push_back(s); 9 | return; 10 | } 11 | 12 | if (open < num) //uncompleted 13 | parentheses(num, open + 1, close, s + "(", list); 14 | if (close < open) 15 | parentheses(num, open, close + 1, s + ")", list); 16 | } 17 | 18 | int main() { 19 | int num; cin >> num; 20 | vector list; 21 | 22 | parentheses(num, 0, 0, "", list); 23 | 24 | for (vector::iterator iter = list.begin(); iter != list.end(); iter++) 25 | cout << *iter << endl; 26 | cout << list.size() << endl; 27 | } 28 | -------------------------------------------------------------------------------- /archive/SeHyeon/extra study bound: -------------------------------------------------------------------------------- 1 | #include 2 | #include //lower_bound, upper_bound 내장 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | //Binary Search 기반의 탐색 방법.(항상 정렬되어 있어야 함) 8 | int arr[] = { 1 ,2 ,3, 4, 6, 7, 8, 9 }; //정렬 되어있어야 함 9 | cout << "lower_bound(4) : " << lower_bound(arr, arr + 8, 4) - arr + 1 << endl; //시작 주소, 끝나는 주소, 키 값 10 | cout << "lower_bound(5) : " << lower_bound(arr, arr + 8, 5) - arr + 1 << endl; //5보다 큰 값이 시작하는 위치 출력 11 | 12 | vector v = { 1 ,2 ,3, 4, 6, 7, 8, 9 }; 13 | cout << "upper_bound(6) : " << upper_bound(v.begin(), v.end(), 6) - v.begin() << endl; // 6보다 작거나 같은 값들이 있는 마지막 위치 14 | cout << "upper_bound(5) : " << upper_bound(v.begin(), v.end(), 5) - v.begin() << endl; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /archive/Coding Practice/No27.txt: -------------------------------------------------------------------------------- 1 | 땅따먹기 게임을 하려고 합니다. 땅따먹기 게임의 땅(land)은 총 N행 4열로 이루어져 있고, 모든 칸에는 점수가 쓰여 있습니다. 1행부터 땅을 밟으며 한 행씩 내려올 때, 각 행의 4칸 중 한 칸만 밟으면서 내려와야 합니다. 단, 땅따먹기 게임에는 한 행씩 내려올 때, 같은 열을 연속해서 밟을 수 없는 특수 규칙이 있습니다. 2 | 3 | 예를 들면, 4 | 5 | | 1 | 2 | 3 | 5 | 6 | 7 | | 5 | 6 | 7 | 8 | 8 | 9 | | 4 | 3 | 2 | 1 | 10 | 11 | 로 땅이 주어졌다면, 1행에서 네번째 칸 (5)를 밟았으면, 2행의 네번째 칸 (8)은 밟을 수 없습니다. 12 | 13 | 마지막 행까지 모두 내려왔을 때, 얻을 수 있는 점수의 최대값을 return하는 solution 함수를 완성해 주세요. 위 예의 경우, 1행의 네번째 칸 (5), 2행의 세번째 칸 (7), 3행의 첫번째 칸 (4) 땅을 밟아 16점이 최고점이 되므로 16을 return 하면 됩니다. 14 | 15 | 제한사항 16 | 행의 개수 N : 100,000 이하의 자연수 17 | 열의 개수는 4개이고, 땅(land)은 2차원 배열로 주어집니다. 18 | 점수 : 100 이하의 자연수 19 | 입출력 예 20 | land answer 21 | [[1,2,3,5],[5,6,7,8],[4,3,2,1]] 16 22 | 입출력 예 설명 23 | 입출력 예 #1 24 | 문제의 예시와 같습니다. 25 | -------------------------------------------------------------------------------- /archive/MoonSeong/210321binaryTranslation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector solution(string s) { 7 | vector answer; 8 | answer.push_back(0); 9 | answer.push_back(0); 10 | 11 | while (s!="1") { 12 | string tempStr = ""; 13 | int notZero = 0; 14 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | int solution(vector scoville, int k) { 6 | int answer = 1; 7 | priority_queue, greater> pq (scoville.begin(), scoville.end()); 8 | 9 | /*for (auto iter = scoville.begin(); iter != scoville.end(); iter++) 10 | pq.push(*iter);*/ 11 | 12 | if (pq.top() >= k) return 0; 13 | for (; ; answer++) { 14 | if (pq.empty()) return -1; 15 | int first = pq.top(); pq.pop(); 16 | if (pq.empty()) return -1; 17 | int second = pq.top(); pq.pop(); 18 | pq.push(first + second * 2); 19 | if (pq.top() >= k) break; 20 | } 21 | 22 | return answer; 23 | } 24 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.07.11 Coding Practice No.65(Compelete).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #pragma warning(disable : 4996) 4 | using namespace std; 5 | 6 | int main() { 7 | vector card; 8 | int cardNum, goal; 9 | int maxSum = -1; 10 | 11 | scanf("%d %d", &cardNum, &goal); 12 | for (int i = 0, tmp; i < cardNum; i++) { 13 | scanf("%d", &tmp); 14 | card.push_back(tmp); 15 | } 16 | for (int i = 0; i < card.size() - 2; i++) { 17 | for (int j = i + 1; j < card.size() - 1; j++) { 18 | for (int k = j + 1; k < card.size(); k++) { 19 | int sum = card[i] + card[j] + card[k]; 20 | 21 | if (sum > goal) 22 | continue; 23 | if (maxSum < sum) 24 | maxSum = sum; 25 | } 26 | } 27 | } 28 | printf("%d", maxSum); 29 | } 30 | -------------------------------------------------------------------------------- /archive/SeHyeon/8-1 jumpGame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 7 3 | using namespace std; 4 | 5 | int n = SIZE, board[SIZE][SIZE] = { 6 | {2, 5, 1, 6, 1, 4, 1}, 7 | {6, 1, 1, 2, 2, 9, 3}, 8 | {7, 2, 3, 2, 1, 3, 1}, 9 | {1, 1, 3, 1, 7, 1, 2}, 10 | {4, 1, 2, 3, 4, 1, 2}, 11 | {3, 3, 1, 2, 3, 4, 1}, 12 | {1, 5, 2, 9, 4, 7, -100} 13 | }; 14 | int cache[SIZE][SIZE]; 15 | 16 | int jump(int y, int x) { 17 | if (y >= n || x >= n) return 0; 18 | if (y == n - 1 && x == n - 1) return 1; 19 | 20 | int& ret = cache[y][x]; 21 | if (ret != -1) return ret; 22 | int jumpSize = board[y][x]; 23 | return ret = (jump(y + jumpSize, x) || jump(y, x + jumpSize)); 24 | } 25 | 26 | int main() { 27 | memset(cache, -1, sizeof(cache)); 28 | cout << jump(0, 0) << endl; 29 | } 30 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/SMUPC/snowballing.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input=sys.stdin.readline 3 | 4 | # N은 앞마당 길이, M은 대회의 시간 5 | N, M = map(int, input().split()) 6 | 7 | # 첫 시작이 0부터 이므로 0을 추가하고 입력 8 | A = [0] + list(map(int, input().split())) 9 | 10 | def DFS(index, size, time): 11 | # 나중에 반환할 정답 12 | global ret 13 | 14 | #시간이 M을 초과하면 끝 15 | if time > M : return 16 | 17 | #시간을 초과하지 않으면 눈덩이 크기 비교해서 최대값 저장 18 | if time <= M : 19 | ret = max(ret, size) 20 | 21 | #눈덩이 굴리기 22 | if index <=N-1: 23 | DFS(index+1, size+A[index+1], time+1) 24 | 25 | #눈덩이 던지기 26 | if index <= N-2: 27 | #눈덩이 크기는 절반 28 | DFS(index+2, size//2 + A[index+2], time+1) 29 | 30 | ret = -1 31 | 32 | DFS(0,1,0) 33 | 34 | print(ret) 35 | -------------------------------------------------------------------------------- /archive/MoonSeong/scoville(timeout).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool compare(int a, int b) { return a > b; } 8 | 9 | int solution(vector scoville, int K) { 10 | int answer = 0; 11 | 12 | while (true) { 13 | sort(scoville.begin(), scoville.end(), compare); 14 | if (scoville.back() > K) 15 | break; 16 | if (scoville.size() < 2) { 17 | answer = -1; 18 | break; 19 | } 20 | 21 | int a = scoville.back(); scoville.pop_back(); 22 | int b = scoville.back(); scoville.pop_back(); 23 | scoville.push_back( a + b * 2 ); 24 | answer++; 25 | } 26 | 27 | return answer; 28 | } 29 | -------------------------------------------------------------------------------- /archive/Coding Practice/No60.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/76501 2 | 3 | 문제 설명 4 | 5 | 어떤 정수들이 있습니다. 이 정수들의 절댓값을 차례대로 담은 정수 배열 absolutes와 이 정수들의 부호를 차례대로 담은 불리언 배열 signs가 매개변수로 주어집니다. 실제 정수들의 합을 구하여 return 하도록 solution 함수를 완성해주세요. 6 | 제한사항 7 | absolutes의 길이는 1 이상 1,000 이하입니다. 8 | absolutes의 모든 수는 각각 1 이상 1,000 이하입니다. 9 | signs의 길이는 absolutes의 길이와 같습니다. 10 | signs[i] 가 참이면 absolutes[i] 의 실제 정수가 양수임을, 그렇지 않으면 음수임을 의미합니다. 11 | 입출력 예 12 | absolutes signs result 13 | [4,7,12] [true,false,true] 9 14 | [1,2,3] [false,false,true] 0 15 | 입출력 예 설명 16 | 입출력 예 #1 17 | signs가 [true,false,true] 이므로, 실제 수들의 값은 각각 4, -7, 12입니다. 18 | 따라서 세 수의 합인 9를 return 해야 합니다. 19 | 입출력 예 #2 20 | signs가 [false,false,true] 이므로, 실제 수들의 값은 각각 -1, -2, 3입니다. 21 | 따라서 세 수의 합인 0을 return 해야 합니다. 22 | -------------------------------------------------------------------------------- /archive/SeHyeon/19.12.16 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define SIZE 5 4 | #define Tri(n) ((n)*((n) + 1))/2 5 | 6 | int main() 7 | { 8 | int arr[SIZE]; for (int i = 0; i < SIZE; i++) cin >> arr[i]; 9 | int saveData[Tri(SIZE)] = { 0, }; 10 | 11 | for (int i = 0; i < SIZE; i++) //삼각수의 일반항 12 | saveData[Tri(i)] = arr[i]; 13 | 14 | int count = -1, standard; 15 | for (int i = 1; i < Tri(SIZE); i++) { 16 | count++; 17 | if (saveData[i] != NULL) { 18 | standard = i; 19 | count = 0; 20 | continue; 21 | } 22 | saveData[i] = saveData[standard] + saveData[standard - count]; 23 | } 24 | 25 | int max = saveData[0]; 26 | for(int i = 1; i < Tri(SIZE); i++) 27 | max = (max < saveData[i] ? saveData[i] : max); 28 | cout << max; 29 | } 30 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.08.10 Coding Practice No.8.cpp: -------------------------------------------------------------------------------- 1 | #define MOD 1234567 2 | using namespace std; 3 | 4 | long long cache[2000]; 5 | 6 | void dpCalc(long long n) { 7 | if (!cache[n]) { 8 | if (!cache[n - 2]) dpCalc(n - 2); 9 | if (!cache[n - 1]) dpCalc(n - 1); 10 | cache[n] = (cache[n - 2] + cache[n - 1]) % MOD; 11 | } 12 | } 13 | 14 | long long solution(int n) { 15 | if (n == 1) return 1; 16 | cache[0] = cache[1] = 1; 17 | dpCalc(n); 18 | 19 | return cache[n] % MOD; 20 | } 21 | 22 | /* 반복문 Ver 23 | long long solution(int n) { 24 | vector dp(n + 1, 0); 25 | dp[1] = 1; 26 | dp[2] = 2; 27 | for (int i = 3; i <= n; i++) 28 | dp[i] = (dp[i - 1] + dp[i - 2]) % 1234567; 29 | return dp[n]; 30 | } 31 | */ 32 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.04.25 Coding Practice No.53.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12949 2 | 3 | #include 4 | using namespace std; 5 | 6 | vector> solution(vector> arr1, vector> arr2) { 7 | int arr1_row = arr1.size(), arr1_column = arr1[0].size(); 8 | int arr2_row = arr2.size(), arr2_column = arr2[0].size(); 9 | 10 | vector> answer(arr1_row, vector(arr2_column)); 11 | for (int i = 0; i < arr1_row; i++) 12 | for (int j = 0; j < arr2_column; j++) { 13 | int val = 0; 14 | for (int pos = 0; pos < arr1_column; pos++) 15 | val += (arr1[i][pos] * arr2[pos][j]); 16 | answer[i][j] = val; 17 | } 18 | return (answer); 19 | } 20 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Kakao/friends4block.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class block 7 | { 8 | private: 9 | bool pop = false; 10 | 11 | public: 12 | block(/* args */); 13 | ~block(); 14 | }; 15 | 16 | block::block(/* args */) 17 | { 18 | } 19 | 20 | block::~block() 21 | { 22 | } 23 | 24 | 25 | int solution(int m, int n, vector board) { 26 | int answer = 0; 27 | vector *playboard = new vector; 28 | int count = 0; 29 | 30 | for (auto i : board) { 31 | for (auto j = 0; j < n; j++) 32 | { 33 | /* code */ 34 | } 35 | 36 | playboard[count].letter = i; 37 | count++; 38 | } 39 | 40 | return answer; 41 | } -------------------------------------------------------------------------------- /Problem/Yutae/B9663(N-Queen).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int N, res = 0; 7 | int a[16]; 8 | 9 | bool check(int cnt) { 10 | for (int i = 0; i < cnt; i++) { 11 | if (a[i] == a[cnt] || abs(a[cnt] - a[i]) == cnt - i) 12 | return false; 13 | } 14 | 15 | return true; 16 | } 17 | 18 | void nqueen(int cnt) { 19 | if (cnt == N) { 20 | res++; 21 | return; 22 | } 23 | 24 | for (int i = 0; i < N; i++) { 25 | a[cnt] = i; 26 | if (check(cnt)) 27 | nqueen(cnt + 1); 28 | } 29 | } 30 | 31 | void solution() { 32 | nqueen(0); 33 | cout << res; 34 | } 35 | 36 | int main(){ 37 | cin >> N; 38 | 39 | solution(); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-4 recognize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int n, m; 5 | int R[100]; 6 | double T[501][501]; 7 | double M[501][501]; 8 | int choice[102][102]; 9 | double cache[102][102]; 10 | //memset(cache, 1, sizeof(cache)); 11 | 12 | double recognize(int segment, int previousMatch) { 13 | if(segment == n) return 0; 14 | double& ret = cache[segment][previousMatch]; 15 | if (ret != 1.0) return ret; 16 | ret = -1e200; 17 | int& choose = choice[segment][previousMatch]; 18 | 19 | for (int thisMatch = 0; thisMatch < m; ++thisMatch) { 20 | double cand = T[previousMatch][thisMatch] + M[thisMatch][R[segment]] + recognize(segment + 1, thisMatch); 21 | if (ret < cand) { 22 | ret = cand; 23 | choose = thisMatch; 24 | } 25 | } 26 | return ret; 27 | } 28 | -------------------------------------------------------------------------------- /archive/ayt/쿼드트리뒤집기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string reverse(string::iterator& it) { 5 | char head = *it; 6 | ++it; 7 | if (head == 'b' || head == 'w') 8 | return string(1, head); 9 | string upperLeft = reverse(it); 10 | string upperRight = reverse(it); 11 | string lowerLeft = reverse(it); 12 | string lowerRight = reverse(it); 13 | return string("x") + lowerLeft + lowerRight + upperLeft + upperRight; 14 | } 15 | 16 | int main() 17 | { 18 | int C; 19 | string input; 20 | string::iterator a; 21 | string result[50]; 22 | cin >> C; 23 | for (int i = 0; i < C; i++) { 24 | cin >> input; 25 | a = input.begin(); 26 | result[i] = reverse(a); 27 | } 28 | for (int i = 0; i < C; i++) { 29 | cout << result[i] << endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /archive/GyuMin/땅따먹기.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/12913?language=cpp 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(vector> land) 9 | { 10 | int MAX = land.size(); 11 | 12 | for (int i = 1; i < MAX; i++) 13 | { 14 | land[i][0] += max(max(land[i - 1][1], land[i - 1][2]), land[i - 1][3]); 15 | land[i][1] += max(max(land[i - 1][0], land[i - 1][2]), land[i - 1][3]); 16 | land[i][2] += max(max(land[i - 1][0], land[i - 1][1]), land[i - 1][3]); 17 | land[i][3] += max(max(land[i - 1][0], land[i - 1][1]), land[i - 1][2]); 18 | } 19 | 20 | return max(max(max(land[MAX - 1][0], land[MAX - 1][1]), land[MAX - 1][2]), land[MAX - 1][3]); 21 | } 22 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/124countries.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(int n) { 7 | string answer = ""; 8 | int numbers[3] = {4, 1, 2}; 9 | while(n > 0) { 10 | answer = to_string(numbers[n%3]) + answer; 11 | if(!(n%3)) { 12 | n = n/3 - 1; 13 | } 14 | else { 15 | n = n/3; 16 | } 17 | } 18 | return answer; 19 | } 20 | 21 | // string solution(int n) { 22 | // string answer = ""; 23 | // int numbers[3] = {1, 2, 4}; 24 | // int temp; 25 | // while(n>0) { 26 | // n-=1; 27 | // temp = n%3; 28 | // answer = to_string(numbers[temp]) + answer; 29 | // n /= 3; 30 | // } 31 | // return answer; 32 | // } -------------------------------------------------------------------------------- /archive/ayt/매프191208.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | int input[5] = { 1,2,3,4,5 }; 6 | int output[5][4] = { {input[1],input[2],input[3],input[4]} 7 | ,{input[0],input[2],input[3],input[4]} 8 | ,{input[0],input[1],input[3],input[4]} 9 | ,{input[0],input[1],input[2],input[4]} 10 | ,{input[0],input[1],input[2],input[3]} 11 | }; 12 | int sum; 13 | 14 | cout << "input : "; 15 | for (int i = 0; i < 5; i++) { 16 | cout << input[i] << ", "; 17 | } 18 | for (int i = 0; i < 5; i++) { 19 | sum = output[i][0] * output[i][1] * output[i][2] * output[i][3]; 20 | input[i] = sum; 21 | } 22 | cout << "\n"; 23 | cout << "output : "; 24 | for (int i = 0; i < 5; i++) { 25 | cout << input[i] << ", "; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/2020_firsthalf/DP200315.cpp: -------------------------------------------------------------------------------- 1 | // 문자열 배열(string array)이 주어지면, 제일 긴 공통된 접두사(prefix)의 길이를 찾으시오. 2 | 3 | 4 | 5 | // Given an array of strings, find the longest common prefix of all strings. 6 | 7 | 8 | 9 | // 예제) 10 | 11 | // Input: [“apple”, “apps”, “ape”] 12 | 13 | // Output: 2 // “ap” 14 | 15 | 16 | 17 | // Input: [“hawaii”, “happy”] 18 | 19 | // Output: 2 // “ha” 20 | 21 | 22 | 23 | // Input: [“dog”, “dogs”, “doge”] 24 | 25 | // Output: 3 // “dog” 26 | 27 | #include 28 | using namespace std; 29 | 30 | void main() 31 | { 32 | char Input[] = ""; 33 | 34 | cout << "Input : ["; 35 | 36 | for (int i = 0; i < 3; i++) 37 | { 38 | cin >> Input; 39 | char *temp; 40 | temp = &Input; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /archive/YoungSeo/가장 큰 정사각형.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int solution(vector> board){ 7 | int answer = board[0][0]; 8 | int row = board.size(); 9 | int col = board[0].size(); 10 | 11 | for(int i = 1; i < row; i++){ 12 | for(int j = 1; j < col; j++){ 13 | 14 | if(board[i][j] == 1){ 15 | 16 | //왼쪽,위,왼쪽위대각선 3개 비교해서 최소값 구한뒤 +1 17 | board[i][j] = min(board[i][j - 1], board[i - 1][j]); 18 | board[i][j] = min(board[i - 1][j - 1], board[i][j]) + 1; 19 | answer = max(answer, board[i][j]); 20 | } 21 | } 22 | } 23 | 24 | 25 | return answer * answer; 26 | } 27 | -------------------------------------------------------------------------------- /archive/ayt/매프200202.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Second(int* in) { 5 | int fir, sec; 6 | fir = in[0]; 7 | if (in[0] < in[1]) 8 | sec = in[0]; //fir이 sec보다 작을 경우 반복문이 끝난후 fir == sec이 되버림 9 | else 10 | sec = in[1]; 11 | for (int i = 1; i < 5; i++) { 12 | if (fir < in[i]){ 13 | if(sec < fir) 14 | sec = fir; 15 | fir = in[i]; 16 | } 17 | else { 18 | if (sec < in[i]) 19 | sec = in[i]; 20 | } 21 | } 22 | if (fir == sec) 23 | cout << "Dose not exist"; 24 | else 25 | cout << sec; 26 | } 27 | 28 | int main() 29 | { 30 | int input[] = { 10,5,4,3,-1 }; 31 | cout << "Input:"; 32 | for(int i = 0; i < 5; i++) 33 | cout << ' ' << input[i]; 34 | cout << "\nOutput: "; 35 | Second(input); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /archive/ayt/백준_근손실.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solution(int K, vector ex) { 8 | int result = 0; 9 | vector id(ex.size()); 10 | 11 | for (int i = 0; i < ex.size(); i++) 12 | id[i] = i; 13 | 14 | do { 15 | int sum = 0; 16 | bool ck = true; 17 | for (auto elem : id) { 18 | sum += (ex[elem] - K); 19 | if (sum < 0) { 20 | ck = false; 21 | break; 22 | } 23 | } 24 | if(ck) result++; 25 | } while (next_permutation(id.begin(), id.end())); 26 | 27 | cout << result; 28 | } 29 | 30 | int main() { 31 | int N, K; 32 | cin >> N >> K; 33 | 34 | vector ex(N); 35 | 36 | for (int i = 0; i < N; i++) 37 | cin >> ex[i]; 38 | 39 | solution(K, ex); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/rotatebracket.py: -------------------------------------------------------------------------------- 1 | def solution(s): 2 | answer = 0 3 | dic = {'{':'}', '[':']', '(':')'} 4 | 5 | for i in range(len(s)): 6 | 7 | right = list(s[i:] + s[:i]) 8 | left = [] 9 | 10 | while right: 11 | 12 | temp = right.pop(0) 13 | 14 | if not left: 15 | left.append(temp) 16 | 17 | else: 18 | if left[-1] in ['}', ')', ']']: 19 | break 20 | if dic[left[-1]] == temp: 21 | left.pop() 22 | else: 23 | left.append(temp) 24 | 25 | if not left: 26 | answer += 1 27 | 28 | return answer 29 | -------------------------------------------------------------------------------- /archive/GyuMin/가장 큰 정사각형.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/18/lessons/1879 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(vector> board) 8 | { 9 | int large = 0; 10 | 11 | int A = board.size(); 12 | int B = board[0].size(); 13 | 14 | if (A == 1 || B == 1) 15 | return 1; 16 | 17 | else 18 | for (int i = 1; i < A; i++) 19 | for (int j = 1; j < B; j++) 20 | { 21 | if (board[i][j] != 0) 22 | board[i][j] = min(min(board[i - 1][j - 1], board[i - 1][j]), board[i][j - 1]) + 1; 23 | 24 | if (board[i][j] > large) 25 | large = board[i][j]; 26 | } 27 | 28 | return large * large; 29 | } 30 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.01.13 matter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | tuple solution(vector input, int target) { 8 | unordered_map map; 9 | tuple answer = make_tuple(-1, -1); 10 | 11 | for (int i = 0; i < input.size(); i++) { 12 | int remain = target - input[i]; 13 | auto search = map.find(remain); 14 | 15 | if (search != map.end()) { 16 | answer = make_tuple(search->second, i); 17 | return answer; 18 | } 19 | map.insert({ input[i], i }); 20 | } 21 | } 22 | 23 | int main() { 24 | vector arr = { 2, 8, 5, 4, 1 }; 25 | int target; cin >> target; 26 | 27 | cout << get<0>(solution(arr, target)) << " " << get<1>(solution(arr, target)) << endl; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.04.18 Coding Practice No.52.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool dfs(int cur, vector>& computers) 5 | { 6 | int index; 7 | 8 | if (!computers[cur][cur]) 9 | return (false); 10 | computers[cur][cur] = 0; 11 | index = 0; 12 | while (index < computers.size()) 13 | { 14 | if (computers[cur][index]) 15 | dfs(index, computers); 16 | index++; 17 | } 18 | return (true); 19 | } 20 | 21 | int solution(int n, vector> computers) { 22 | int answer = 0; 23 | int i; 24 | 25 | i = 0; 26 | while (i < n) 27 | { 28 | if (computers[i][i]) 29 | if (dfs(i, computers)) 30 | answer++; 31 | i++; 32 | } 33 | return (answer); 34 | } 35 | -------------------------------------------------------------------------------- /archive/ayt/매프191208-2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int input[5] = { 1,2,3,4,5 }; 7 | int input1[] = { 8 | 1, 9 | input[0], 10 | input[0] * input[1], 11 | input[0] * input[1] * input[2], 12 | input[0] * input[1] * input[2] * input[3] 13 | }; 14 | int input2[] = { 15 | input[1] * input[2] * input[3] * input[4], 16 | input[2] * input[3] * input[4], 17 | input[3] * input[4], 18 | input[4], 19 | 1 20 | }; 21 | int Output[5]; 22 | for (int i = 0; i < 5; i++) 23 | Output[i] = input1[i] * input2[i]; 24 | 25 | cout << "Input: "; 26 | for (int i = 0; i < 5; i++) 27 | cout << input[i] << " "; 28 | cout << endl; 29 | 30 | cout << "Output: "; 31 | for (int i = 0; i < 5; i++) 32 | cout << Output[i] << " "; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /archive/Coding Practice/No28.txt: -------------------------------------------------------------------------------- 1 | 1와 0로 채워진 표(board)가 있습니다. 표 1칸은 1 x 1 의 정사각형으로 이루어져 있습니다. 표에서 1로 이루어진 가장 큰 정사각형을 찾아 넓이를 return 하는 solution 함수를 완성해 주세요. (단, 정사각형이란 축에 평행한 정사각형을 말합니다.) 2 | 3 | 예를 들어 4 | 5 | 1 2 3 4 6 | 0 1 1 1 7 | 1 1 1 1 8 | 1 1 1 1 9 | 0 0 1 0 10 | 가 있다면 가장 큰 정사각형은 11 | 12 | 1 2 3 4 13 | 0 1 1 1 14 | 1 1 1 1 15 | 1 1 1 1 16 | 0 0 1 0 17 | 가 되며 넓이는 9가 되므로 9를 반환해 주면 됩니다. 18 | 19 | 제한사항 20 | 표(board)는 2차원 배열로 주어집니다. 21 | 표(board)의 행(row)의 크기 : 1,000 이하의 자연수 22 | 표(board)의 열(column)의 크기 : 1,000 이하의 자연수 23 | 표(board)의 값은 1또는 0으로만 이루어져 있습니다. 24 | 입출력 예 25 | board answer 26 | [[0,1,1,1],[1,1,1,1],[1,1,1,1],[0,0,1,0]] 9 27 | [[0,0,1,1],[1,1,1,1]] 4 28 | 입출력 예 설명 29 | 입출력 예 #1 30 | 위의 예시와 같습니다. 31 | 32 | 입출력 예 #2 33 | | 0 | 0 | 1 | 1 | 34 | | 1 | 1 | 1 | 1 | 35 | 로 가장 큰 정사각형의 넓이는 4가 되므로 4를 return합니다. 36 | -------------------------------------------------------------------------------- /archive/Coding Practice/No79.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/42885 2 | 3 | 구명보트 4 | 문제 설명 5 | 무인도에 갇힌 사람들을 구명보트를 이용하여 구출하려고 합니다. 구명보트는 작아서 한 번에 최대 2명씩 밖에 탈 수 없고, 무게 제한도 있습니다. 6 | 7 | 예를 들어, 사람들의 몸무게가 [70kg, 50kg, 80kg, 50kg]이고 구명보트의 무게 제한이 100kg이라면 2번째 사람과 4번째 사람은 같이 탈 수 있지만 1번째 사람과 3번째 사람의 무게의 합은 150kg이므로 구명보트의 무게 제한을 초과하여 같이 탈 수 없습니다. 8 | 9 | 구명보트를 최대한 적게 사용하여 모든 사람을 구출하려고 합니다. 10 | 11 | 사람들의 몸무게를 담은 배열 people과 구명보트의 무게 제한 limit가 매개변수로 주어질 때, 모든 사람을 구출하기 위해 필요한 구명보트 개수의 최솟값을 return 하도록 solution 함수를 작성해주세요. 12 | 13 | 제한사항 14 | 무인도에 갇힌 사람은 1명 이상 50,000명 이하입니다. 15 | 각 사람의 몸무게는 40kg 이상 240kg 이하입니다. 16 | 구명보트의 무게 제한은 40kg 이상 240kg 이하입니다. 17 | 구명보트의 무게 제한은 항상 사람들의 몸무게 중 최댓값보다 크게 주어지므로 사람들을 구출할 수 없는 경우는 없습니다. 18 | 입출력 예 19 | people limit return 20 | [70, 50, 80, 50] 100 3 21 | [70, 80, 50] 100 3 22 | -------------------------------------------------------------------------------- /archive/GyuMin/더 맵게.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/42626 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(vector scoville, int K) 9 | { 10 | int answer = 0; 11 | 12 | int A, B; 13 | 14 | priority_queue, greater> queue; 15 | 16 | for (int i = 0; i < scoville.size(); i++) 17 | queue.push(scoville[i]); 18 | 19 | while (queue.top() <= K) 20 | { 21 | A = queue.top(); 22 | queue.pop(); 23 | 24 | B = queue.top(); 25 | queue.pop(); 26 | 27 | queue.push(A + 2 * B); 28 | 29 | answer++; 30 | 31 | if ((queue.size() == 1) && (queue.top() < K)) 32 | return -1; 33 | } 34 | 35 | return answer; 36 | } 37 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/DP200817.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isfourpower(int input) { 5 | int editinput = input / 4; 6 | if (editinput == 1) { 7 | return true; 8 | } 9 | else if(editinput == 0) { 10 | return false; 11 | } 12 | return isfourpower(editinput); 13 | } 14 | 15 | int main() { 16 | int input; 17 | do { 18 | cout << "input : "; cin >> input; 19 | if (input <= 0) { 20 | cout << "Input number must bigger than 0" << endl; 21 | cout << "input : "; cin >> input; 22 | } 23 | } while (input == NULL); 24 | if (isfourpower(input)) { 25 | cout << "Output : true"; 26 | } 27 | else { 28 | cout << "Output : false"; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /archive/Coding Practice/No52.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/43162 2 | 3 | 문제 설명 4 | 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있을 때 컴퓨터 A와 컴퓨터 C도 간접적으로 연결되어 정보를 교환할 수 있습니다. 따라서 컴퓨터 A, B, C는 모두 같은 네트워크 상에 있다고 할 수 있습니다. 5 | 6 | 컴퓨터의 개수 n, 연결에 대한 정보가 담긴 2차원 배열 computers가 매개변수로 주어질 때, 네트워크의 개수를 return 하도록 solution 함수를 작성하시오. 7 | 8 | 제한사항 9 | 컴퓨터의 개수 n은 1 이상 200 이하인 자연수입니다. 10 | 각 컴퓨터는 0부터 n-1인 정수로 표현합니다. 11 | i번 컴퓨터와 j번 컴퓨터가 연결되어 있으면 computers[i][j]를 1로 표현합니다. 12 | computer[i][i]는 항상 1입니다. 13 | 입출력 예 14 | n computers return 15 | 3 [[1, 1, 0], [1, 1, 0], [0, 0, 1]] 2 16 | 3 [[1, 1, 0], [1, 1, 1], [0, 1, 1]] 1 17 | 입출력 예 설명 18 | 예제 #1 19 | 아래와 같이 2개의 네트워크가 있습니다. 20 | image0.png 21 | 22 | 예제 #2 23 | 아래와 같이 1개의 네트워크가 있습니다. 24 | image1.png 25 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Kakao/secretmap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector solution(int n, vector arr1, vector arr2) { 8 | vector answer; 9 | 10 | string temp; 11 | string tempboard; 12 | int startpoint = 0; 13 | for (int i = 0; i < n; i++) { 14 | bitset<16> temp1 = arr1[i]; 15 | bitset<16> temp2 = arr2[i]; 16 | bitset<16> temp_bit = temp1 | temp2; 17 | 18 | temp = temp_bit.to_string(); 19 | tempboard = ""; 20 | startpoint = 16-n; 21 | for (int j = startpoint; j < 16; j++) { 22 | temp[j] == '1' ? tempboard += '#' : tempboard += " "; 23 | } 24 | answer.push_back(tempboard); 25 | } 26 | return answer; 27 | } -------------------------------------------------------------------------------- /archive/ayt/매프191110.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int substring(char a[50]) { 6 | bool clear = false; 7 | vector b; 8 | int result = 0; 9 | 10 | b.push_back(a[0]); 11 | for (int i = 0; i < strlen(a); i++) { 12 | if (i == 0 && a[0] != a[1]) { 13 | clear = false; 14 | } 15 | for (int j = 0; j < b.size(); j++) { 16 | if (b.at(j) == a[i]) 17 | clear = true; 18 | } 19 | if (clear == true) 20 | b.clear(); 21 | else if (clear == false && i != 0) 22 | b.push_back(a[i]); 23 | if (result < b.size()) 24 | result = b.size(); 25 | clear = false; 26 | } 27 | return result; 28 | } 29 | int main() { 30 | char input[50]; 31 | int result; 32 | 33 | cin >> input; 34 | result = substring(input); 35 | cout << result; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /archive/ayt/백준_창영이와점프.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solve(int N, int K, vector dis) { 8 | int result = -1; 9 | 10 | for (int i = 0; i < dis.size();i++) { 11 | int cur = 1; 12 | bool jump = true; 13 | 14 | for (int j = i; j < dis.size(); j++) { 15 | if (dis[j] <= K) 16 | ++cur; 17 | else { 18 | if (jump) { 19 | jump = false; 20 | ++cur; 21 | } 22 | else 23 | break; 24 | } 25 | } 26 | result = (cur > result) ? cur : result; 27 | } 28 | 29 | cout << result; 30 | } 31 | 32 | int main() { 33 | int N, K; 34 | cin >> N >> K; 35 | 36 | vector dis(N-1); 37 | 38 | for (int i = 0; i < N - 1; i++) 39 | cin >> dis[i]; 40 | 41 | solve(N, K, dis); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /archive/Coding Practice/No57.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/77885 2 | 3 | 문제 설명 4 | 양의 정수 x에 대한 함수 f(x)를 다음과 같이 정의합니다. 5 | 6 | x보다 크고 x와 비트가 1~2개 다른 수들 중에서 제일 작은 수 7 | 예를 들어, 8 | 9 | f(2) = 3 입니다. 다음 표와 같이 2보다 큰 수들 중에서 비트가 다른 지점이 2개 이하이면서 제일 작은 수가 3이기 때문입니다. 10 | 수 비트 다른 비트의 개수 11 | 2 000...0010 12 | 3 000...0011 1 13 | f(7) = 11 입니다. 다음 표와 같이 7보다 큰 수들 중에서 비트가 다른 지점이 2개 이하이면서 제일 작은 수가 11이기 때문입니다. 14 | 수 비트 다른 비트의 개수 15 | 7 000...0111 16 | 8 000...1000 4 17 | 9 000...1001 3 18 | 10 000...1010 3 19 | 11 000...1011 2 20 | 정수들이 담긴 배열 numbers가 매개변수로 주어집니다. numbers의 모든 수들에 대하여 각 수의 f 값을 배열에 차례대로 담아 return 하도록 solution 함수를 완성해주세요. 21 | 22 | 제한사항 23 | 1 ≤ numbers의 길이 ≤ 100,000 24 | 0 ≤ numbers의 모든 수 ≤ 1015 25 | 입출력 예 26 | numbers result 27 | [2,7] [3,11] 28 | 입출력 예 설명 29 | 입출력 예 #1 30 | 31 | 문제 예시와 같습니다. 32 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.05.18 Coding Practice No.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char change(char c, int n) { 4 | if (c == ' ') return ' '; 5 | for (int i = 0; i < n; i++) { 6 | c++; 7 | if (c > 'Z' && c < 'a') c = 'A'; 8 | if (c > 'z') c = 'a'; 9 | } 10 | return c; 11 | } 12 | 13 | string solution(string s, int n) { 14 | for (int i = 0; i < s.size(); i++) 15 | s[i] = change(s[i], n); 16 | return s; 17 | } 18 | 19 | //char change(char c, int n) { 20 | // if (c == ' ') return ' '; 21 | // bool large = false; 22 | // if (c >= 'A' && c <= 'Z') large = true; 23 | // c += n; //It is impossible that adding at once 24 | // if (c > 'z') c -= ('z' - 'a' + 1); 25 | // if (c > 'Z' && large) c -= ('z' - 'a' + 1); 26 | // 27 | // return c; 28 | //} 29 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-10 KLis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MAX = 2000000000 + 1; 5 | int n; 6 | int cacheLen[501], cacheCnt[501], S[500]; 7 | 8 | int lis(int start) { 9 | int& ret = cacheLen[start + 1]; 10 | if (ret != -1) return ret; 11 | ret = 1; 12 | for (int next = start + 1; next < n; ++next) 13 | if (start == -1 || S[start] < S[next]) 14 | ret = max(ret, lis(next) + 1); 15 | return ret; 16 | } 17 | 18 | int count(int start) { 19 | if (lis(start) == 1) return 1; 20 | int& ret = cacheCnt[start + 1]; 21 | if (ret != -1) return ret; 22 | ret = 0; 23 | for (int next = start + 1; next < n; ++next) { 24 | if ((start == -1 || S[start] < S[next]) && lis(start) == list(next) + 1) 25 | ret = min(MAX, (long long)ret + count(next)); 26 | } 27 | return ret; 28 | } 29 | -------------------------------------------------------------------------------- /archive/MoonSeong/primeNum2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int solution(int[] nums) { 3 | int answer = 0; 4 | // 모든 서로다른 3개의 수의 합을 구함: O(n^3) 5 | for (int i = 0; i < nums.length - 2; i++) 6 | for (int j = i + 1; j < nums.length - 1; j++) { 7 | for (int k = j + 1; k < nums.length; k++) { 8 | if (Solution.isPrimeNum(nums[i] + nums[j] + nums[k])) answer++; 9 | } 10 | } 11 | return answer; 12 | } 13 | 14 | static boolean isPrimeNum(int num) { 15 | if (num == 2) return true; 16 | if (num % 2 == 0) return false; 17 | 18 | for (int i = 3; i <= Math.sqrt(num); i++) 19 | if (num % i == 0) return false; 20 | //END OF LOOP 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_N-Queen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void findNQ(int n, int j, int& answer) { 7 | for(int i=0;i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector solution(vector answers) { 8 | vector answer; 9 | vector> spz = { 10 | {1,2,3,4,5}, 11 | {2,1,2,3,2,4,2,5}, 12 | {3,3,1,1,2,2,4,4,5,5} 13 | }; 14 | vector result = {0,0,0}; 15 | 16 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | const int MAX = 2000000000 + 1; 6 | int n; 7 | int cacheLen[501], cacheCnt[501], S[500]; 8 | 9 | void reconstruct(int start, int skip, vector& lis) { 10 | if (start != -1) lis.push_back(S[start]); 11 | vector> followers; 12 | for (int next = start + 1; next < n; ++next) 13 | if ((start == -1 || S[start] < S[next]) && lis(start) == lis(next) + 1) 14 | followers.push_back(make_pair(S[next], next)); 15 | sort(followers.begin(), followers.end()); 16 | 17 | for (int i = 0; i < followers.size(); i++) { 18 | int idx = followers[i].second; 19 | int cnt = count(idx); 20 | if (cnt <= skip) skip -= cnt; 21 | else { 22 | reconstruct(idx, skip, lis); 23 | break; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /archive/SeHyeon/19.11.10 matter Ver init.cpp: -------------------------------------------------------------------------------- 1 | //한 문자로 지속되는 문자열 구별x 2 | //서로 다른 문자여도 앞에서 기록한 문자열인 경우 개수를 셈 ex) abcabc 정답 : 3 (코드 : 6) 3 | //끊어졌다가 시작하는경우도 계속 개수를 셈 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int subString(string input, int max, char prechar = NULL) 10 | { 11 | int output = 0; 12 | 13 | if(input.length() == 0) 14 | return 0; 15 | 16 | if (input.length() == max) { 17 | return output += subString(input.substr(1), max, input[0]); 18 | } 19 | else { 20 | if (prechar == input[0]) return 0 + subString(input.substr(1), max, input[0]); 21 | else return 1 + subString(input.substr(1), max, input[0]); 22 | 23 | } 24 | } 25 | 26 | int main() 27 | { 28 | string input; 29 | cin >> input; 30 | 31 | int result = subString(input, input.length()); 32 | cout << result << endl; 33 | } 34 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.06.06 Coding Practice No.58(Time out - DP).cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12980 2 | 3 | #include 4 | using namespace std; 5 | 6 | bool powerOfTwo(int n) { 7 | int i; 8 | 9 | i = 1; 10 | while (i <= n) { 11 | if (i == n) 12 | return (true); 13 | i *= 2; 14 | } 15 | return (false); 16 | } 17 | 18 | int solution(int n) { 19 | int* dp; 20 | int i; 21 | 22 | dp = (int*)malloc(sizeof(int) * (n + 1)); 23 | i = 0; 24 | while (i <= n) { 25 | if (powerOfTwo(i)) 26 | dp[i] = 1; 27 | else { 28 | if (i % 2 == 0) 29 | dp[i] = dp[i / 2]; 30 | else 31 | dp[i] = dp[i - 1] + 1; 32 | } 33 | i++; 34 | } 35 | 36 | return (dp[n]); 37 | } 38 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/DP200831.cpp: -------------------------------------------------------------------------------- 1 | // 1~N 까지 있는 정수 배열에 원소 하나가 없어졌습니다. 없어진 원소의 값을 구하시오. 2 | 3 | 4 | 5 | // Given an integer array of 1~N except one number, find the missing integer. 6 | 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | int main() { 12 | 13 | int N; int missing_number; 14 | cout << "Type N : "; cin >> N; 15 | 16 | int *numbers = new int[N]; 17 | 18 | for (int i = 0; i < N; i++) { 19 | numbers[i] = i + 1; 20 | } 21 | 22 | srand((unsigned int)time(0)); 23 | missing_number = rand() % N; 24 | 25 | numbers[missing_number] = 0; 26 | 27 | int i = 0; int point; 28 | 29 | do { 30 | point = numbers[i]; 31 | i++; 32 | } while ( point != 0 ); 33 | 34 | cout << "answer is " << --i; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /archive/SeHyeon/9-9 Morse Code(kth).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 3 | using namespace std; 4 | 5 | const int M = 1000000000 + 100; 6 | int bino[201][201]; 7 | int skip; 8 | 9 | void calcBino() { 10 | memset(bino, 0, sizeof(bino)); 11 | for (int i = 0; i <= 200; i++) { 12 | bino[i][0] = bino[i][i] = 1; 13 | for (int j = 1; j < i; j++) 14 | bino[i][j] = MIN(M, bino[i - 1][j - 1] + bino[i - 1][j]); 15 | } 16 | } 17 | 18 | string kth(int n, int m, int skip) { 19 | if (n == 0) return string(m, 'o'); 20 | if (skip < bino[n + m - 1][n - 1]) return "-" + kth(n - 1, m, skip); 21 | return "o" + kth(n, m - 1, skip - bino[n + m - 1][n - 1]); 22 | } 23 | 24 | int main() { 25 | int k; cin >> k; skip = k; 26 | int n, m; cin >> n >> m; 27 | 28 | calcBino(); 29 | cout << kth(n, m, skip) << endl; 30 | } 31 | -------------------------------------------------------------------------------- /archive/Coding Practice/No13.txt: -------------------------------------------------------------------------------- 1 | 수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 2 | 3 | 1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ... 4 | 2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ... 5 | 3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ... 6 | 7 | 1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요. 8 | 9 | 제한 조건 10 | 시험은 최대 10,000 문제로 구성되어있습니다. 11 | 문제의 정답은 1, 2, 3, 4, 5중 하나입니다. 12 | 가장 높은 점수를 받은 사람이 여럿일 경우, return하는 값을 오름차순 정렬해주세요. 13 | 입출력 예 14 | answers return 15 | [1,2,3,4,5] [1] 16 | [1,3,2,4,2] [1,2,3] 17 | 입출력 예 설명 18 | 입출력 예 #1 19 | 20 | 수포자 1은 모든 문제를 맞혔습니다. 21 | 수포자 2는 모든 문제를 틀렸습니다. 22 | 수포자 3은 모든 문제를 틀렸습니다. 23 | 따라서 가장 문제를 많이 맞힌 사람은 수포자 1입니다. 24 | 25 | 입출력 예 #2 26 | 27 | 모든 사람이 2문제씩을 맞췄습니다. 28 | -------------------------------------------------------------------------------- /archive/Coding Practice/No39.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/12915 2 | 3 | 문제 설명 4 | 문자열로 구성된 리스트 strings와, 정수 n이 주어졌을 때, 각 문자열의 인덱스 n번째 글자를 기준으로 오름차순 정렬하려 합니다. 예를 들어 strings가 [sun, bed, car]이고 n이 1이면 각 단어의 인덱스 1의 문자 u, e, a로 strings를 정렬합니다. 5 | 6 | 제한 조건 7 | strings는 길이 1 이상, 50이하인 배열입니다. 8 | strings의 원소는 소문자 알파벳으로 이루어져 있습니다. 9 | strings의 원소는 길이 1 이상, 100이하인 문자열입니다. 10 | 모든 strings의 원소의 길이는 n보다 큽니다. 11 | 인덱스 1의 문자가 같은 문자열이 여럿 일 경우, 사전순으로 앞선 문자열이 앞쪽에 위치합니다. 12 | 입출력 예 13 | strings n return 14 | [sun, bed, car] 1 [car, bed, sun] 15 | [abce, abcd, cdx] 2 [abcd, abce, cdx] 16 | 입출력 예 설명 17 | 입출력 예 1 18 | sun, bed, car의 1번째 인덱스 값은 각각 u, e, a 입니다. 이를 기준으로 strings를 정렬하면 [car, bed, sun] 입니다. 19 | 20 | 입출력 예 2 21 | abce와 abcd, cdx의 2번째 인덱스 값은 c, c, x입니다. 따라서 정렬 후에는 cdx가 가장 뒤에 위치합니다. abce와 abcd는 사전순으로 정렬하면 abcd가 우선하므로, 답은 [abcd, abce, cdx] 입니다. 22 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/2020_firsthalf/DP200427_another.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool check(int *input, int casenum) { 5 | int start = 0; 6 | int nextnum; 7 | for (int i = 0; i < casenum+1; i++) 8 | { 9 | nextnum = input[input[start]]; 10 | } 11 | 12 | if (nextnum == input[start]) 13 | { 14 | return true; 15 | } 16 | else 17 | { 18 | return false; 19 | } 20 | } 21 | 22 | int main() { 23 | int casenum; 24 | 25 | cout << "Testcase : "; 26 | cin >> casenum; 27 | 28 | int *input = new int[casenum]; 29 | 30 | cout << "Input : ["; 31 | 32 | int i = 0; 33 | 34 | while (input == NULL) 35 | { 36 | cin >> input[i]; 37 | i++; 38 | } 39 | 40 | cout << "Output : " << check(input, casenum); 41 | 42 | } -------------------------------------------------------------------------------- /archive/Coding Practice/No11.txt: -------------------------------------------------------------------------------- 1 | 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 2 | 3 | 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수들의 이름이 담긴 배열 completion이 주어질 때, 완주하지 못한 선수의 이름을 return 하도록 solution 함수를 작성해주세요. 4 | 5 | 제한사항 6 | 마라톤 경기에 참여한 선수의 수는 1명 이상 100,000명 이하입니다. 7 | completion의 길이는 participant의 길이보다 1 작습니다. 8 | 참가자의 이름은 1개 이상 20개 이하의 알파벳 소문자로 이루어져 있습니다. 9 | 참가자 중에는 동명이인이 있을 수 있습니다. 10 | 입출력 예 11 | participant completion return 12 | [leo, kiki, eden] [eden, kiki] leo 13 | [marina, josipa, nikola, vinko, filipa] [josipa, filipa, marina, nikola] vinko 14 | [mislav, stanko, mislav, ana] [stanko, ana, mislav] mislav 15 | 입출력 예 설명 16 | 예제 #1 17 | leo는 참여자 명단에는 있지만, 완주자 명단에는 없기 때문에 완주하지 못했습니다. 18 | 19 | 예제 #2 20 | vinko는 참여자 명단에는 있지만, 완주자 명단에는 없기 때문에 완주하지 못했습니다. 21 | 22 | 예제 #3 23 | mislav는 참여자 명단에는 두 명이 있지만, 완주자 명단에는 한 명밖에 없기 때문에 한명은 완주하지 못했습니다. 24 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.10.30 Coding Practice No.18.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int solution(string skill, vector skill_trees) { 6 | int answer = 0; 7 | map skillTable; 8 | 9 | for (int i = 0; i < skill.size(); i++) 10 | skillTable[skill[i]] = i; 11 | 12 | for (int i = 0; i < skill_trees.size(); i++) { 13 | bool flag = true; 14 | int learn = 0; 15 | for (int j = 0; j < skill_trees[i].size(); j++) { 16 | if (skillTable.find(skill_trees[i][j]) == skillTable.end()) continue; 17 | if (learn < skillTable.find(skill_trees[i][j])->second) { 18 | flag = false; 19 | break; 20 | } 21 | learn++; 22 | } 23 | if (flag) answer++; 24 | } 25 | 26 | return answer; 27 | } 28 | -------------------------------------------------------------------------------- /archive/SeHyeon/21.09.12 Coding Practice No.81.cpp: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/84512 2 | 3 | const char charset[] = { 'A', 'E', 'I', 'O', 'U' }; 4 | const int expr[] = { 781, 156, 31, 6, 1 }; 5 | 6 | int solution(string word) { 7 | int answer = 0; 8 | 9 | for (int i = 0; i < word.size(); i++) { 10 | int index; 11 | 12 | for (index = 0; index < 5; index++) 13 | if (charset[index] == word[i]) 14 | break; 15 | answer += (expr[i] * (index) + 1); 16 | } 17 | 18 | return answer; 19 | } 20 | 21 | //#include 22 | //using namespace std; 23 | 24 | //int solution(string word) { 25 | // int answer = 0; 26 | // 27 | // for (int i = 0; i < word.size(); i++) 28 | // answer += string("AEIOU").find(word[i]) * expr[i] + 1; 29 | // return answer; 30 | //} 31 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_튜플.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector solution(string s) { 8 | vector answer; 9 | map m; 10 | string tmp = ""; 11 | 12 | for (int i = 0; i < s.size(); ++i) { 13 | if ('0' <= s[i] && s[i] <= '9') { 14 | tmp += s[i]; 15 | } 16 | else if (tmp != "") { 17 | if (m.find(tmp) == m.end()) m[tmp] = 1; 18 | else ++m[tmp]; 19 | tmp = ""; 20 | } 21 | } 22 | 23 | int si = m.size(); 24 | while (1) { 25 | if (answer.size() == si) break; 26 | string tmp = ""; 27 | int tmp2 = 0; 28 | 29 | for (auto iter : m) { 30 | if (iter.second > tmp2) { 31 | tmp = iter.first; 32 | tmp2 = iter.second; 33 | } 34 | } 35 | 36 | m.erase(m.find(tmp)); 37 | answer.push_back(stoi(tmp)); 38 | } 39 | 40 | return answer; 41 | } 42 | -------------------------------------------------------------------------------- /archive/SongChiHoon/OnBook/LIS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int cache[101], S[101], choices[101]; 7 | 8 | int lis4 (int start) { 9 | int &ret = cache[start+1]; 10 | if(ret != -1) return ret; 11 | 12 | ret = 1; 13 | int bestNext = -1; 14 | for (int next = start + 1; next < n; ++next) { 15 | if(start == -1 || S[start] < S[next]) { 16 | int cand = lis4(next) + 1; 17 | if(cand > ret) { 18 | ret = cand; 19 | bestNext = next; 20 | } 21 | } 22 | } 23 | choices[start + 1] = bestNext; 24 | return ret; 25 | } 26 | 27 | void reconstruct (int start, vector &seq) { 28 | if(start != -1) seq.push_back(S[start]); 29 | int next = choices[start + 1]; 30 | if(next != -1) reconstruct(next, seq); 31 | } -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Hash/Hash-phonecalllist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool solution(vector phone_book) { 7 | bool answer = true; 8 | string temp, comp; 9 | int smallsize = 987654321; 10 | int smallindex = 0; 11 | 12 | for (int i = 0; i < phone_book.size(); i++) { 13 | if(phone_book[i].size() < smallsize) { 14 | smallsize = phone_book[i].length(); 15 | smallindex = i; 16 | } 17 | } 18 | 19 | temp = phone_book[smallindex]; 20 | 21 | for(int i = 0; i < phone_book.size(); i++) { 22 | if (i != smallindex) { 23 | comp = phone_book[i].substr(0, smallsize); 24 | if(temp == comp) { 25 | return false; 26 | } 27 | } 28 | } 29 | return answer; 30 | } -------------------------------------------------------------------------------- /archive/YoungSeo/N진수게임.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | string Convert_To_N(int a, int n){ 8 | string result = ""; 9 | char list[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; 10 | 11 | while(a/b!=0){ 12 | result= list[a%n]+result; 13 | a/=b;} 14 | 15 | result = list[a%n] +result; 16 | return result; 17 | } 18 | 19 | 20 | 21 | string solution(int n, int t, int m, int p) { 22 | string answer = ""; 23 | string tmp=""; 24 | 25 | for(int i=0;i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int solution(string skill, vector skill_trees) { 7 | int answer = 0; 8 | string tmp; 9 | bool tf = true; 10 | 11 | for (int i = 0; i < skill_trees.size(); ++i) { 12 | for (int j = 0; j < skill_trees[i].size(); ++j) 13 | for (int z = 0; z < skill.size(); ++z) 14 | if (skill[z] == skill_trees[i][j]) 15 | tmp += skill_trees[i][j]; 16 | 17 | for(int j=0;j 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int solution(int cacheSize, vector cities) { 8 | int answer = 0; 9 | list cache; 10 | 11 | if (cacheSize == 0) return cities.size() * 5; 12 | for (auto fetch : cities) { 13 | transform(fetch.begin(), fetch.end(), fetch.begin(), ::tolower); 14 | if (find(cache.begin(), cache.end(), fetch) != cache.end()) { 15 | answer += 1; 16 | cache.erase(find(cache.begin(), cache.end(), fetch)); 17 | cache.push_back(fetch); 18 | } 19 | else { 20 | if (cache.size() >= cacheSize) cache.pop_front(); 21 | cache.push_back(fetch); 22 | answer += 5; 23 | } 24 | } 25 | 26 | return answer; 27 | } 28 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Daily_Programming/2020_firsthalf/DP200113.cpp: -------------------------------------------------------------------------------- 1 | // 정수 배열과 타겟 숫자가 주어지면, 합이 타겟값이 되는 두 원소의 인덱스를 찾으시오. 2 | 3 | // 단, 시간복잡도 O(n) 여야 합니다. 4 | 5 | // Given an array of integers and a target integer, find two indexes of the array element that sums to the target number. 6 | 7 | // 예제) 8 | 9 | // Input: [2, 5, 6, 1, 10], 타겟 8 10 | 11 | // Output: [0, 2] // 배열[0] + 배열[2] = 8 12 | 13 | #include 14 | #define SIZE 5 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | int target = 8; 20 | int input[SIZE] = {2, 5, 6, 1, 10}; 21 | int result_value = 0; 22 | 23 | cout << "Input : ["; 24 | for(int i = 0; i < SIZE; i++) 25 | { 26 | cout << input[i] << " "; 27 | } 28 | cout << "]" << endl; 29 | 30 | for (int i = 0; i < SIZE; i++) 31 | { 32 | result_value = input 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Problem/Yutae/Week1/B1074(Z).cpp: -------------------------------------------------------------------------------- 1 | // https://www.acmicpc.net/problem/1074 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int N, r, c; 9 | int num[4]; 10 | 11 | int main() { 12 | cin >> N >> r >> c; 13 | 14 | int start = 0; 15 | while (1) { 16 | for (int i = 0; i < 4; i++) 17 | num[i] = i * pow(2, 2 * N - 2) + start; 18 | 19 | if (N == 1) break; 20 | 21 | int half = pow(2, N - 1); 22 | if (r < half && c < half) 23 | start = num[0]; 24 | else if (r < half && c >= half) { 25 | start = num[1]; 26 | c -= half; 27 | } 28 | else if (r >= half && c < half) { 29 | start = num[2]; 30 | r -= half; 31 | } 32 | else if (r >= half && c >= half) { 33 | start = num[3]; 34 | c -= half; 35 | r -= half; 36 | } 37 | N--; 38 | } 39 | 40 | cout << num[2 * r + c] << "\n"; 41 | 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /archive/Coding Practice/No81.txt: -------------------------------------------------------------------------------- 1 | https://programmers.co.kr/learn/courses/30/lessons/84512 2 | 3 | 모음 사전 4 | 문제 설명 5 | 사전에 알파벳 모음 'A', 'E', 'I', 'O', 'U'만을 사용하여 만들 수 있는, 길이 5 이하의 모든 단어가 수록되어 있습니다. 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA"이며, 마지막 단어는 "UUUUU"입니다. 6 | 7 | 단어 하나 word가 매개변수로 주어질 때, 이 단어가 사전에서 몇 번째 단어인지 return 하도록 solution 함수를 완성해주세요. 8 | 9 | 제한사항 10 | word의 길이는 1 이상 5 이하입니다. 11 | word는 알파벳 대문자 'A', 'E', 'I', 'O', 'U'로만 이루어져 있습니다. 12 | 입출력 예 13 | word result 14 | "AAAAE" 6 15 | "AAAE" 10 16 | "I" 1563 17 | "EIO" 1189 18 | 입출력 예 설명 19 | 입출력 예 #1 20 | 21 | 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA", "AAA", "AAAA", "AAAAA", "AAAAE", ... 와 같습니다. "AAAAE"는 사전에서 6번째 단어입니다. 22 | 23 | 입출력 예 #2 24 | 25 | "AAAE"는 "A", "AA", "AAA", "AAAA", "AAAAA", "AAAAE", "AAAAI", "AAAAO", "AAAAU"의 다음인 10번째 단어입니다. 26 | 27 | 입출력 예 #3 28 | 29 | "I"는 1563번째 단어입니다. 30 | 31 | 입출력 예 #4 32 | 33 | "EIO"는 1189번째 단어입니다. 34 | -------------------------------------------------------------------------------- /archive/GyuMin/멀쩡한사각형.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/62048# 2 | using namespace std; 3 | 4 | long long solution(int w, int h) 5 | { 6 | long long answer = (long long)w * (long long)h; 7 | 8 | long long gcd; 9 | 10 | if (w == h) 11 | answer -= w; 12 | 13 | else 14 | { 15 | if (w > h) 16 | for (long long i = 1; i <= h; i++) 17 | { 18 | if (((long long)w % i == 0) && ((long long)h % i == 0)) 19 | gcd = i; 20 | } 21 | 22 | else 23 | for (long long i = 1; i <= w; i++) 24 | { 25 | if (((long long)w % i == 0) && ((long long)h % i == 0)) 26 | gcd = i; 27 | } 28 | 29 | answer -= gcd * ((w / gcd) + (h / gcd) - 1); 30 | } 31 | 32 | return answer; 33 | } 34 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Pipemoving.cpp: -------------------------------------------------------------------------------- 1 | // N*N 사이즈의 집이 있다. 이곳의 (0,0), (0,1) 좌표에 파이프가 놓여있다. 2 | 3 | // 파이프의 이동 가능 방법 4 | 5 | // 파이프는 항상 우측 하단을 향해 내려가야 한다. 6 | 7 | // 가로 : 가로, 45도 대각선. 8 | 9 | // 세로 : 세로, 45도 대각선. 10 | 11 | // 대각선 : 가로, 세로, 45도 대각선. 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | struct pipe 20 | { 21 | int pipe[2] = {1, 1}; 22 | }; 23 | 24 | int main() 25 | { 26 | int housesize; 27 | cin >> housesize; 28 | 29 | int **house = new int*[housesize]; 30 | 31 | for (int i = 0; i < housesize; i++) 32 | house[i] = new int [housesize]; 33 | 34 | for (int i = 0; i < housesize; i++) 35 | { 36 | for (int j = 0; j < housesize; j++) 37 | { 38 | cin >> house[i][j]; 39 | } 40 | 41 | } 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /archive/MoonSeong/210424findSquare(timeOut).py: -------------------------------------------------------------------------------- 1 | def isExpansable(board, level): 2 | next = False 3 | nextBoard = [[0 for x in range(len(board[0]) - 1)] for y in range(len(board) - 1)] 4 | 5 | for y in range(len(board) - 1): 6 | for x in range(len(board[0]) - 1): 7 | if board[y][x] == 1 and board[y+1][x] == 1 and board[y][x+1] == 1 and board[y+1][x+1] == 1: 8 | next = True 9 | nextBoard[y][x] = 1 10 | 11 | if next: 12 | return isExpansable(nextBoard, level + 1) 13 | else: 14 | return level*level 15 | 16 | def solution(board): 17 | sum = 0 18 | for y in range(len(board)): 19 | for x in range(len(board[0])): 20 | sum += board[y][x] 21 | 22 | if sum == 0: 23 | answer = 0 24 | else: 25 | answer = isExpansable(board, 1) 26 | 27 | return answer 28 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.12.27 Coding Practice No.28(Compelete).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int solution(vector> board) { 6 | int answer = 0; 7 | if (board.size() == 1 || board[0].size() == 1) { 8 | for (int x = 0; x < board[0].size(); x++) if (board[0][x]) return 1; 9 | for (int y = 0; y < board.size(); y++) if (board[y][0]) return 1; 10 | return 0; 11 | } 12 | for (int y = 1; y < board.size(); y++) 13 | for (int x = 1; x < board[0].size(); x++) { 14 | if (!board[y][x]) continue; 15 | int minValue = min(board[y - 1][x - 1], board[y - 1][x]); 16 | minValue = min(minValue, board[y][x - 1]); 17 | board[y][x] = ++minValue; 18 | if (minValue > answer) answer = minValue; 19 | } 20 | return answer * answer; 21 | } 22 | -------------------------------------------------------------------------------- /Problem/Yutae/B1182(부분순열의합).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int N, S, res = 0; 8 | int n[21]; 9 | int tmp[21]; 10 | 11 | void combination(int index, int depth,int r) { 12 | if (depth == r) { 13 | int sum = 0; 14 | for (auto elem : tmp) { 15 | sum += elem; 16 | } 17 | if (sum == S) res++; 18 | 19 | return; 20 | } 21 | 22 | for (int i = index; i < N; i++) { 23 | tmp[depth] = n[i]; 24 | combination(i + 1, depth + 1, r); 25 | } 26 | } 27 | 28 | void solution() { 29 | for (int i = 1; i <= N; i++) 30 | combination(0, 0, i); 31 | cout << res; 32 | } 33 | 34 | int main(){ 35 | cin >> N >> S; 36 | 37 | for (int i = 0; i < N; i++) { 38 | cin >> n[i]; 39 | } 40 | 41 | solution(); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Kakao/CraneKakao.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int solution(vector> board, vector moves) { 7 | int answer = 0; 8 | 9 | vector collecting; 10 | 11 | vector>::iterator row; 12 | vector::iterator col; 13 | 14 | for(row = board.begin(); row != board.end(); row++) 15 | { 16 | for(col = row->begin(); col != row->end(); col++) 17 | { 18 | if(*col == 0) 19 | { 20 | continue; 21 | } 22 | else 23 | { 24 | collecting.push_back(*col); 25 | if(col == --col) 26 | { 27 | answer++; 28 | *col = 0; 29 | } 30 | } 31 | } 32 | } 33 | return answer; 34 | } 35 | -------------------------------------------------------------------------------- /archive/YoungSeo/오픈채팅방.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | map m; 7 | 8 | vector solution(vector record) 9 | { 10 | vector answer; 11 | string id, name, key; 12 | stringstream ss; 13 | 14 | for(int i=0;i> key; ss >> id; ss >> name; 18 | if(key == "Enter" ){ 19 | m[id] = name; 20 | answer.push_back(name + "님이 들어왔습니다."); 21 | } 22 | else if(key == "Leave"){ 23 | answer.push_back(name + "님이 나갔습니다."); 24 | m[id] = name;} 25 | else(key == "Change"){ 26 | ss>>id; 27 | ss>>name; 28 | m[id]= name; 29 | } 30 | 31 | 32 | 33 | 34 | return answer;} 35 | } 36 | -------------------------------------------------------------------------------- /archive/ayt/매프200824.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int x = 5, y = 32; 5 | 6 | typedef struct TreeNode { 7 | int data; 8 | struct TreeNode* left, * right; 9 | }TreeNode; 10 | 11 | TreeNode n1 = { 3,NULL,NULL }; 12 | TreeNode n2 = { 12,NULL,NULL }; 13 | TreeNode n3 = { 7,&n1,&n2 }; 14 | TreeNode n4 = { 21,NULL,NULL }; 15 | TreeNode n5 = { 31,NULL,NULL }; 16 | TreeNode n6 = { 26,&n4,&n5 }; 17 | TreeNode n7 = { 18,&n2,&n6 }; 18 | TreeNode* root = &n7; 19 | // 18 20 | // 7 26 21 | // 3 12 21 31 22 | 23 | void findNode(TreeNode* root) { 24 | if (root == NULL) 25 | return; 26 | if (root->data > x&& root->data < y) 27 | cout << root->data << " "; 28 | 29 | findNode(root->left); 30 | findNode(root->right); 31 | } 32 | 33 | int main() { 34 | findNode(root); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.09.07 Coding Practice No.11(Not Success Ver2).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | string solution(vector participant, vector completion) { 7 | sort(participant.begin(), participant.end()); 8 | sort(completion.begin(), completion.end()); 9 | 10 | int startLine = 0; 11 | for (int i = 0; i < participant.size(); i++) { 12 | bool check = false; 13 | for (int j = startLine; j < completion.size(); j++) { 14 | if (participant[i][0] < completion[j][0]) { 15 | break; 16 | } 17 | if (participant[i] == completion[j]) { 18 | completion[j] = ""; 19 | check = true; 20 | break; 21 | } 22 | } 23 | if (!check) return participant[i]; 24 | } 25 | return ""; 26 | } 27 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Programmers/Kakao/ndigitgame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | string solution(int n, int t, int m, int p) { 7 | string answer = ""; 8 | 9 | string temp = ""; 10 | int present_number = 0; 11 | int current_number = 0; 12 | int remainder = 0; 13 | int ordercounter = 0; 14 | 15 | while (true) { 16 | current_number = present_number / n; 17 | while( current_number == 0) { 18 | remainder = present_number % n; 19 | 20 | // 숫자를 글자로 변환해서 넣어두기 21 | 22 | } 23 | 24 | if(ordercounter % m == p - 1) { 25 | answer.append(temp[]); 26 | } 27 | if(answer.length() == t) { 28 | break; 29 | } 30 | else { 31 | ordercounter++; 32 | present_number++; 33 | } 34 | } 35 | return answer; 36 | } -------------------------------------------------------------------------------- /archive/GyuMin/위장.cpp: -------------------------------------------------------------------------------- 1 | //https://programmers.co.kr/learn/courses/30/lessons/42578# 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool compare(vector a, vector b) 9 | { 10 | return a[1] < b[1]; 11 | } 12 | 13 | int solution(vector> clothes) 14 | { 15 | int answer = 1; 16 | 17 | int x = 1; 18 | 19 | vector cat; 20 | 21 | sort(clothes.begin(), clothes.end(), compare); 22 | 23 | for (int i = 0; i < clothes.size() - 1; i++) 24 | if (clothes[i][1] == clothes[i + 1][1]) 25 | x++; 26 | 27 | else 28 | { 29 | cat.push_back(x + 1); 30 | x = 1; 31 | } 32 | 33 | cat.push_back(x + 1); 34 | 35 | for (int i = 0; i <= cat.size(); i++) 36 | answer *= cat[i]; 37 | 38 | answer--; 39 | 40 | return answer; 41 | } 42 | -------------------------------------------------------------------------------- /archive/MoonSeong/blackjack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #pragma warning(disable:4996) 5 | 6 | using namespace std; 7 | 8 | int main(void) { 9 | int n, m; 10 | scanf("%d %d", &n, &m); 11 | 12 | vector cards; 13 | for (int i = 0; i < n; i++) { 14 | int card; 15 | scanf("%d", &card); 16 | cards.push_back(card); 17 | } 18 | 19 | sort(cards.begin(), cards.end()); 20 | 21 | int res = 0; 22 | for (int i = 0; i < n - 2; i++) 23 | for (int j = i + 1; j < n - 1; j++) 24 | for (int k = j + 1; k < n; k++) { 25 | int sum = cards[i] + cards[j] + cards[k]; 26 | if (sum > m) 27 | continue; 28 | else 29 | res = sum > res ? sum : res; 30 | } 31 | cout << res; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /archive/YoungSeo/수포자.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | vector solution(vector answers) { 5 | vector answer; 6 | vector answer1 {1, 2, 3, 4, 5}; 7 | vector answer2 {2, 1, 2, 3, 2, 4, 2, 5}; 8 | vector answer3 {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; 9 | int count1 = 0; 10 | int count2 = 0; 11 | int count3 = 0; 12 | int size = answers.size(); 13 | for(int i = 0; i < size; ++i) { 14 | int i1=i%5; 15 | int i2=i%8; 16 | int i3=i%10; 17 | 18 | if(answers[i] == answer1[i1]) count1++; 19 | if(answers[i] == answer2[i2]) count2++; 20 | if(answers[i] == answer3[i3]) count3++; } 21 | int maxCount = max(count1, max(count2, count3)); 22 | if(maxCount == count1) 23 | answer.push_back(1); 24 | if(maxCount == count2) answer.push_back(2); 25 | if(maxCount == count3) answer.push_back(3); 26 | return answer; 27 | } 28 | -------------------------------------------------------------------------------- /archive/ayt/프로그래머스_실패율.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool compare(pair& a, pair& b) { 8 | if (a.first == b.first) return a.second < b.second; 9 | return a.first > b.first; 10 | } 11 | 12 | vector solution(int N, vector stages) { 13 | vector answer; 14 | vector> p; 15 | int si = stages.size(); 16 | 17 | for (int i = 0; i < N; ++i) { 18 | double tmp = 0; 19 | for (int j = 0; j < stages.size(); ++j) 20 | if (stages[j] == i + 1) ++tmp; 21 | if (tmp == 0) p.push_back(make_pair(0, i + 1)); 22 | else p.push_back(make_pair(tmp / si, i + 1)); 23 | si -= tmp; 24 | } 25 | 26 | sort(p.begin(), p.end(), compare); 27 | for (auto elem : p) answer.push_back(elem.second); 28 | 29 | return answer; 30 | } 31 | -------------------------------------------------------------------------------- /archive/Kimsh/mailprogramming_0202: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include //greater(정렬 기준을 내림차순으로 바꿔 주는) 함수 객체를 사용하기 위한 헤더 4 | #include 5 | #pragma warning (disable : 4996) 6 | using namespace std; 7 | // 정수 배열(int array)이 주어지면 두번째로 큰 값을 프린트하시오. 8 | //Input: [3, 3, 3] Input: [10, 5, 4, 3, -1] 9 | 10 | set > Input = { 10, 5, 4, 3, -1 }; //들어간 값을 내림차순으로 정렬 11 | 12 | int main() { 13 | set ::iterator itor; //이렇게 해서 itorator을 가져올 수 있음! 14 | itor = Input.begin(); 15 | if (Input.size() >= 2) { 16 | cout << *(++itor)<< endl; 17 | } 18 | else { cout << "두번째로 큰 값이 없습니다.\n"; } 19 | getchar(); 20 | return 0; 21 | } 22 | 23 | 24 | 25 | /* 26 | functional STL의 함수 객체들 27 | 28 | less : 첫번째 인자가 두번째 인자보다 작으면 true 반환 (bool) 29 | greater : 첫번째 인자가 두번째 인자보다 크면 true 반환 (bool) 30 | 31 | plus : 두개의 인자를 더한 값 반환 32 | minus : 첫번째 인자에서 두번째 인자를 뺀 값 반환 33 | 34 | */ 35 | -------------------------------------------------------------------------------- /archive/SeHyeon/20.06.15 matter.cpp: -------------------------------------------------------------------------------- 1 | //This problem is good at STACK 2 | #include 3 | #define UNDO "../" 4 | #define CUR "./" 5 | 6 | using namespace std; 7 | 8 | string pwd(string input) { 9 | string output, tmp = "", beforeSave = ""; 10 | output = '/'; 11 | bool calc = false; 12 | 13 | for (int i = 1; input[i] != NULL; i++) { 14 | tmp += input[i]; 15 | 16 | if (input[i] == '/') calc = true; 17 | else if (input[i + 1] == NULL) { 18 | tmp += '/'; calc = true; 19 | } 20 | 21 | if (calc) { 22 | if (tmp == UNDO) beforeSave = ""; 23 | else if (tmp == CUR); 24 | else { 25 | output += beforeSave; 26 | beforeSave = tmp; 27 | } 28 | tmp = ""; calc = false; 29 | } 30 | } 31 | 32 | output += beforeSave; 33 | return output; 34 | } 35 | 36 | int main() { 37 | string input; cin >> input; 38 | string output = pwd(input); 39 | cout << output << endl; 40 | } 41 | -------------------------------------------------------------------------------- /archive/SeHyeon/9-17 waveBarJim(DP).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MOD = 1000000007; 5 | 6 | string e, digits; 7 | int n, m; 8 | int cache[1 << 14][20][2]; 9 | 10 | int price(int index, int taken, int mod, int less) { 11 | if (index == n) return (less && mod == 0) ? 1 : 0; 12 | int& ret = cache[taken][mod][less]; 13 | if (ret != -1) return ret; 14 | ret = 0; 15 | for(int next = 0; next < n; ++next) 16 | if ((taken & (1 << next)) == 0) { 17 | if(!less && e[index] < digits[next]) continue; 18 | if (next > 0 && digits[next - 1] == digits[next] && (taken & (1 << (next - 1))) == 0) continue; 19 | 20 | int nextTaken = taken | (1 < next); 21 | int nextMod = (mod * 10 + digits[next] - '0') % m; 22 | int nextLess = less || e[index] > digits[next]; 23 | 24 | ret += price(index + 1, nextTaken, nextMod, nextLess); 25 | ret %= MOD; 26 | } 27 | return ret; 28 | } 29 | -------------------------------------------------------------------------------- /archive/SongChiHoon/Baekjoon/SMUPC/neednewfriend.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | sys.setrecursionlimit(1234568) 4 | H, W = map(int, input().split()) 5 | a, b = -1, -1 6 | g = [] 7 | 8 | for i in range(H): 9 | t = list(input()) 10 | if 'I' in t: 11 | a, b = i, t.index('I') 12 | g.append(t) 13 | 14 | v = [[0] * W for i in range(H)] 15 | 16 | dy = 1, -1, 0, 0 17 | dx = 0, 0, 1, -1 18 | cnt = 0 19 | 20 | def dfs(y, x): 21 | global cnt 22 | v[y][x] = 1 23 | 24 | for i in range(4): 25 | 26 | ty, tx = y + dy[i], x + dx[i] 27 | 28 | if not (0 <= ty < H and 0 <= tx < W): 29 | continue 30 | if v[ty][tx]: 31 | continue 32 | if g[ty][tx] == 'X': 33 | continue 34 | if g[ty][tx] == 'P': 35 | cnt += 1 36 | dfs(ty, tx) 37 | 38 | dfs(a, b) 39 | print(cnt if cnt else "TT") 40 | -------------------------------------------------------------------------------- /archive/YoungSeo/스킬트리.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int solution(string skill, vector skill_trees) { 7 | 8 | int answer = 0; 9 | for(int i = 0; i < skill_trees.size(); i++) { 10 | vector temp; 11 | 12 | for(int j = 0; j < skill_trees[i].size(); j++) { 13 | for(int k = 0; k < skill.size(); k++) { 14 | if(skill[k] == skill_trees[i][j]) { 15 | temp.push_back(skill_trees[i][j]); 16 | } 17 | } 18 | } 19 | 20 | int flag = 0; 21 | for(int j = 0; j < temp.size(); j++) { 22 | if(temp[j] != skill[j]) { 23 | flag = 1; 24 | break; 25 | } 26 | } 27 | 28 | if(flag == 0) { 29 | answer++; 30 | } 31 | } 32 | return answer; 33 | } 34 | --------------------------------------------------------------------------------