본문 바로가기

Algorithm/Implementation

(750)
(C++) - 백준(BOJ) 17863 : FYI https://www.acmicpc.net/problem/17863 17863번: FYI In the United States of America, telephone numbers within an area code consist of 7 digits: the prefix number is the first 3 digits and the line number is the last 4 digits. Traditionally, the 555 prefix number has been used to provide directory informatio www.acmicpc.net if문을 써보는 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 문자열 s를 선언 후 입력받습니다. 📔 풀이과정 substr로 앞 3글자..
(C++) - 백준(BOJ) 14038 : Tournament Selection https://www.acmicpc.net/problem/14038 14038번: Tournament Selection The output will be either 1, 2, 3 (to indicate which Group the player should be placed in) or -1 (to indicate the player has been eliminated). www.acmicpc.net 입력과 if문을 사용해보는 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 6개의 문자 info를 입력 받습니다. 📔 풀이과정 info가 'W'라면 winCnt를 1씩 증가시켜줍니다. 📔 정답출력 조건에 따라 정답을 출력해줍니다. 📕 Code #include using namespace std; int win..
(C++) - 백준(BOJ) 11549번 : Identifying tea https://www.acmicpc.net/problem/11549 11549번: Identifying tea The first line contains an integer T representing the tea type (1 ≤ T ≤ 4). The second line contains five integers A, B, C, D and E, indicating the answer given by each contestant (1 ≤ A, B, C, D, E ≤ 4). www.acmicpc.net for문과 if문을 사용해보는 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 cnt, n, 5개의 정수를 입력해줍니다. n은 tea의 이름이 정수형태로 표현된 값입니다. 📔 풀이과정 5개 정수를 입력할 때마..
(C++) - 프로그래머스(월간 코드 챌린지 시즌3) : 없는 숫자 더하기 https://programmers.co.kr/learn/courses/30/lessons/86051 코딩테스트 연습 - 없는 숫자 더하기 0부터 9까지의 숫자 중 일부가 들어있는 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요. 제한 programmers.co.kr for, if문을 써보는 간단한 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 나온 숫자를 체크하기 위한 일차원 배열 ck를 선언합니다. 📔 풀이과정 1. numbers를 순회하면서 나온 수를 index로 하여 해당 값을 ck[index] = 1로 만들어줍니다. 2. ck를 순회하며 0인 부분을 answer에 모두..
(C++) - 백준(BOJ) 14467번 : 소가 길을 건너간 이유 1 https://www.acmicpc.net/problem/14467 14467번: 소가 길을 건너간 이유 1 3번 소는 위치 1, 0, 1에서 관찰되었으므로 길을 최소 두 번 건넜음을 확인할 수 있다. 4번 소도 길을 한 번 건넜으며, 나머지 소는 길을 건넌 기록이 확인되지 않는다. www.acmicpc.net 반복문과 분기문을 사용해보는 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 10마리 소의 위치를 나타낼 일차원 배열 cow, 관찰 횟수 n, 정답을 출력할 변수 ans를 int형으로 선언합니다. cow의 값을 -1로 초기화해줍니다. 📔 풀이과정 매 루프마다 a, b를 선언 후 입력합니다. a는 소의 번호, b는 소의 위치를 의미합니다. 1. 처음 소의 위치가 -1인 경우에는 소의 초기 위치를 정한..
(C++) - 프로그래머스(2020 카카오 인턴십) : 키패드 누르기 https://programmers.co.kr/learn/courses/30/lessons/67256 코딩테스트 연습 - 키패드 누르기 [1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5] "right" "LRLLLRLLRRL" [7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2] "left" "LRLLRRLLLRR" [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] "right" "LLRLLRLLRL" programmers.co.kr 구현문제였습니다. 📕 풀이방법 📔 풀이과정 누른 번호목록이 저장되어 있는 numbers를 순회하며 답 변수 answer에 적절히 답 문자들을 뒤에 붙여주는 방식으로 구현했습니다. 1. 1, 4, 7의 경우는 왼손 2. 3, 6, 9의 경우 오른손 3. ..
(C++) - 백준(BOJ) 6764번 : Sounds fishy! https://www.acmicpc.net/problem/6764 6764번: Sounds fishy! The output is one of four possibilities. If the depth readings are increasing, then the output should be Fish Rising. If the depth readings are decreasing, then the output should be Fish Diving. If the depth readings are identical, then the output should b www.acmicpc.net 분기문을 사용하는 문제였습니다. 📕 풀이방법 📔 정답출력 수의 개수가 4개로 적기 때문에 하드코딩으로 조건에 따라 출력해..
(C++) - 백준(BOJ) 16926번 : 배열 돌리기 1 https://www.acmicpc.net/problem/16926 16926번: 배열 돌리기 1 크기가 N×M인 배열이 있을 때, 배열을 돌려보려고 한다. 배열은 다음과 같이 반시계 방향으로 돌려야 한다. A[1][1] ← A[1][2] ← A[1][3] ← A[1][4] ← A[1][5] ↓ ↑ A[2][1] A[2][2] ← A[2][3] ← A[2][4] A[2][5] www.acmicpc.net 구현(simulation) 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 n, m, r입력 후 n행 m열에 대해 매번 수를 입력받고 이차원 배열 arr에 저장합니다. 📔 풀이과정 좌상의 점, 우하의 점 이 두개의 점을 특정짓는다면 사각형이 그려집니다. 이 사각형의 테두리를 min(m,n)/2번 특정지어 ..