분류 전체보기
-
2. Search(선형 검색 & 이진 검색)Data Structure 2022. 1. 21. 17:06
알고리즘 및 자료 구조 정리 두 번째는 검색방법이다. 두 가지의 검색 방법을 제시하는데, 선형 검색과 이진 검색이다. 1. 선형 검색 - 요소가 직선 모양으로 늘어선 배열에서의 검색으로 원하는 키 값을 갖는 요소를 만날 때까지 맨 앞부터 순서대로 요소를 검색하는 알고리즘 arr 배열에서의 모습을 보면 arr 배열 6 4 3 2 1 3 8 에서 처음 부터 순서대로 검색하여 원하는 수가 있으면, 검색 성공!! 아니면, 검색 실패!! 이러한 예시를 통해서 while문과 for문으로 각각 선언한 선형 검색법을 알아 볼 수 있다. 위 예시에서 제시한 선형 검색법은 종료 조건을 만족하기 위해 두 가지의 조건을 체크해야한다. 검색값을 발견하지 못 하고 배열의 끝을 지나간 경우 검색할 값과 같은 요소를 발견한 경우 이..
-
1/21기록 - 백준 1546Algorithm 2022. 1. 21. 10:49
오늘은 브론즈 1 문제에서 평균이라는 글자가 눈에 띄어서 백준 1546번 평균 문제를 도전해 보았다. 학교 과제나 각종 언어책 예제에서 과목 평균 문제는 정말 많이 다루기 때문에 문제를 보자 마자 익숙하긴 했다. 꿀 빤 느낌... 오늘의 문제이다. 문제를 읽으면서 익숙하다는 느낌도 받았지만, 세준이란 놈이 어이가 없다는 생각만 계속 했던거 같다. 도대체 어디서 나온 점수 계산법인지... ㅋㅋㅋㅋㅋ 알고리즘 생각 1. 배열을 하나 선언해서 숫자를 모두 입력받는다. 2. 배열에 선언된 수 중 max 변수와 비교를 하여 배열에 선언된 수가 max 변수값 보다 더 크면 max에 배열에 선언된 수를 넣어준다. 3. sum 변수에 성적을 모두 담아준다. 4. 문제에서 원하는 계산법 대로 총합 성적을 산출하고 과목 ..
-
1/20기록 - 백준 1110Algorithm 2022. 1. 20. 15:32
2박 3일의 제주도 여행을 끝내고 돌아오자 마자 한 문제를 풀고 쉬기로 했다. 나와의 약속이니까!!! 오늘은 지난번 포스팅에서 말했었기 때문에 브론즈1을 도전해 보았다. 백준 1110번 더하기 사이클 문제 처음 문제를 읽으면서 수열 문제인가 생각했는데, 그게 아니었다. 문제에서 주어진 규칙대로 새로운 수를 만들고 그렇게 만들어진 수가 처음 입력한 수와 동일하면 종료시키는 문제였다. 이 문제는 알고리즘을 짜면서 사실상 문제를 다 풀었다. 알고리즘 짜는게 그냥 끝인 문제이기 때문에... 알고리즘 생각 1. 입력 예시를 통해 살펴 보니 26 -> 68(26의 일의자리가 새로운 수의 10의 자리, 2+6이 새로운 수의 일의 자리) 그렇다면, 26 -> 26%10 = 6(일의자리) * 10 = 6이 10의 자리로..
-
1/18기록 #2 - 백준 1159Algorithm 2022. 1. 18. 10:21
생각보다 이전 문제가 너무 빠르게 해결이 되어서 한 문제를 더 풀어 보기로 했다. 이번 문제는 백준 1159번 문제 농구경기 문제이다. 잡다한 설명들은 제외하고 맨 처음 알파벳이 5개 이상인지 아닌지를 판단하면 되는 문제이다. 2학기 자바프로그래밍 중간고사에서 알파벳 문제가 대놓고 나온 적이 있어서, 아스키 코드 값을 시작 지점은 기억하고 있었다. a는 97이란거, 그리고 알파벳은 총 26개라는 거... 사실 이거만 알면 문제 길이에 비해 너무 간단했다. 알고리즘 생각. 1. 26크기의 알파벳을 담을 수 있는 배열을 선언. 2. 반복문을 돌릴 N을 입력 받고, N크기의 for문을 만들어 String 변수에 수 많은 알파벳을 담아줌. 3. 변수.charAt(0) 메소드를 이용하여 문자열의 제일 처음 문자를..
-
1/18기록 #1 - 백준 1075번Algorithm 2022. 1. 18. 10:06
1/18일 제주도 여행을 떠나기 전 아침에 빠르게 문제를 하나 풀어 보았다. 백준 1075번 나누기 문제이다. 문제는 정말 간단하다 N과 F를 입력 받고, N을 F로 나누었을 때 N의 맨 뒤 두자리를 조작하여 나누어 떨어질 수 있는 수를 만드는 것이다. 맨 처음 든 생각은 갑자기 맨 뒤 두 자리를 어떻게 바꾸지...?? 였는데, 맨 뒤 두 자리에 초점을 맞추어 계속 생각하다 보니 맨 뒤 두 자리를 그냥 00으로 만들어 초기화 시켜 놓고 시작하면 될 듯 싶었다. 알고리즘 생각 1. 맨 뒤 두 자리를 00으로 초기화 시킨다. 2. 반복문 안에서 N이 F로 나누어 떨어질 때, N을 100으로 나눈 나머지 값을 출력하자. 3. 값이 10보다 작으면 02 이런식으로 출력해야 하므로, 출력 형식에 맞게 출력해주면 ..
-
1/17기록 - 프로그래머스 2018 카카오 코테#2Algorithm 2022. 1. 17. 10:35
즐겁게 놀고 난 주말 이후 월요일 아침에 도전해본 2018 카카오 코테 level 1 비밀지도 문제 일단 문제가 엄청나게 길었다. 긴 문제들을 잘 읽어 보면 벽은 #으로 길은 공백으로 표현되고, 이진수로 표현했다가 출력은 String 형태의 #과 공백으로 표현하면 되는거다. 긴 문제에 비해 이해하는 건 매우 쉬웠음. 알고리즘 생각 1. n길이의 answer 배열 선언 2. Integer.toBinaryString()을 이용해서 이진수로 변환 3. arr1과 arr2배열의 합집합으로 최종 지도가 완성되기 때문에 비트 연산자 or(|)를 사용 4. replace(old, new)를 사용해서 old를 new로 변환 5. 맨 앞이 공백인 경우에 대한 표현 이렇게 풀었다. 이 문제에서 toBinaryString(..
-
1/14기록 - 프로그래머스 카카오 코테 #1Algorithm 2022. 1. 14. 11:05
알고리즘 스터디에서 카카오 코딩테스트 문제를 풀어보자는 말을 듣고, 프로그래머스에서 2018 level1 다트 게임 문제를 도전해 보았다. 카카오는 카카오다... 거의 죽는 줄 알았다. 문제도 길고 내용 이해가 되었는데 내 마음대로 구현하니 실행도 안 되고 프로그래머스 특성상 밑줄도 안 그어지고...... 총체적 난국 2시간 반만에 문제를 풀었다. 이래가지고 카카오 도전도 못할듯...ㅠㅠ 여튼 문제로 들어가보자. 일단 문제부터 엄청나게 길다. 처음에는 조건을 읽다가 무슨 소리야 하면서 입출력 예제와 비교해 가며 읽어보니 문제가 이해가 되었다. 간단하게 정리해보면 1. 숫자 0~9는 그대로 숫자를 적는다. 2. S는 1제곱, D는 2제곱, T는 3제곱을 해 준다. 3. #은 해당 수에 -1을 곱한다. 4...
-
1. 동적 배열Data Structure 2022. 1. 13. 15:51
C언어 자료 구조에 대해서 공부를 시작했는데, 공부를 하면서 정리 차원에서 포스팅을 해볼까 한다. 자료구조 첫번째는 배열에 대한 소개이다. 배열에 대해서는 자바 언어 List 포스팅 및 최근의 백준 문제풀이에서도 정말 많이 볼 수 있는 것이므로 일반적인 것 외에 내가 몰랐던 방식들을 조금씩 정리하고자 한다. 배열이란? 같은 자료형의 변수로 이루어진 요소가 모여 직선 모양으로 줄지어 있는 자료 구조. ex) int arr[5] -> 크기 5의 arr이름을 가진 int 타입의 배열 **배열 요소 개수 구하기 sizeof(a)/sizeof(a[0]) : 요소의 개수 구하는 공식 sizeof(a)로 전체 배열이 할당된 메모리 크기를 구하고, sizeof(a[0])로 첫 번째 요소가 할당된 메모리 크기를 구한다...