분류 전체보기
-
1/28기록 - 백준 1094Algorithm 2022. 1. 28. 09:59
브론즈는 어느정도 됐다고 생각해서 실버5를 도전해보고 있는데 오늘도 실버 5에서 한 문제를 도전해 보았다. 오늘은 백준 1094번 막대기 문제이다. 문제는 이러하다. 처음에 읽으면서 이게 뭔 소린가 하면서 3~4번을 다시 읽었던 것 같은데, 결국 예제 입력을 보면서 문제에서 주어진 방식을 하나씩 따라 가다 보니 완벽히 이해를 할 수 있었다. 예제 입력 1을 보면 23을 입력받았고, 64부터 계속 반복해서 나눈 막대기값은 32, 16, 8, 4, 2, 1 이다. 여기서 16, 4, 2, 1을 조합하면 23을 만들어 낼 수 있다. 그래서 조합한 막대기 개수는 4개. 예제 입력 2를 보면 32의 경우 64, 32 에서 바로 32 하나를 가지고 만들 수 있으므로 조합한 막대기 수는 1개가 된다. 알고리즘 생각 ..
-
3. Stack(스택)Data Structure 2022. 1. 27. 14:15
스택이란? - 데이터를 일시적으로 저장하기 위해 사용하는 자료구조, 후입선출의 개념이다. 이처럼 push를 통해 자료를 담을 수도 있고, pop을 통해 자료를 빼서 반환할 수도 있다. 후입선출의 개념이기 때문에 LIFO 방식이라고도 부른다. 스택에 대한 다양한 메소드를 살펴보자 1. 초기화 함수 Initialize : 스택의 메모리 공간(배열)을 확보하는 등의 준비 작업을 수행하는 함수, 배열을 위한 메모리 공간을 만들 때 스택은 반드시 비어 있어야 한다. 2. Push : 데이터 추가 함수. 3. Pop : 데이터 제거 함수. 4. Peek : 스택 꼭대기의 데이터를 몰래 엿보는 함수. 입력과 출력이 없으므로 스택 포인터는 변화하지 않는다. 5. Clear : 스택에 쌓여 있는 모든 데이터를 삭제하는 ..
-
1/27기록 - 프로그래머스 2019 KaKao 코딩테스트(실패율)Algorithm 2022. 1. 27. 09:40
오늘은 스터디원들과 함께 풀었던 2019 카카오 코테의 level1 문제였던 실패율 문제를 마저 풀어보았다. 문제가 상당히 길다. 위 문제를 잘 살펴 보면, stages[] 배열과 스테이지 개수를 통해서 실패율을 따로 정의하고 그 실패율을 토대로 result[] 배열을 내림차순으로 출력시키라는 것이 결론이다. 꽤나 복잡한 요소들이 많아서 아이패드에 직접 메모를 해 놓고 문제를 풀었다. 거의 알고리즘에 대한 생각을 모두 했다. 처음엔 실패율과 stage개수를 엮어서 Map으로 풀 수 있지 않을까 생각을 했지만 그 이후로 아무 생각도 나지 않아서 그냥 포기하고 원론적으로 풀게 되었다. 개인적으로 생각할 때 5번 부터가 가장 중요한데, 내림차순으로 개수를 배열하기 위해서 메소드를 사용하지 않고는 어떻게 할 수..
-
1/25기록 - 백준 2161Algorithm 2022. 1. 25. 09:24
오늘의 포스팅은 백준 2161번 카드1 문제이다. 이 문제를 솔직히 보자마자 내 첫 포스팅이던 요세푸스 문제가 떠올랐다. 선입선출의 개념으로 Queue를 이용해서 풀면 깔끔할 것 같았다. 제일 처음에는 Queue와 ArrayList를 활용해서 Queue에서 poll() 메소드로 뽑은 수를 ArrayList에 담아서 list를 출력시키려고 생각했는데, 예제 출력 상 중간에 띄워져 있는 부분이 있어서 list만 출력시키면 안될 듯 하여 그냥 Queue만으로 문제를 풀고, StringBuilder에 append하여 출력시키는 방식을 생각했다. 알고리즘 생각 1. Queue를 활용한다. 2. N을 입력받고 for문으로 N만큼 선언된 Queue에 add() 시켜 준다. 3. isEmpty() 메소드를 사용하여 w..
-
1/24기록 - 백준 1357Algorithm 2022. 1. 24. 11:02
오늘은 즐겁고 상쾌한지 잘 모르겠는 월요일이다.... 문제를 살펴보다가 제목이 너무 마음에 드는 문제가 있어서 문제를 풀어 보았다. 제목은 다름 아닌 뒤집힌 덧셈 ㅋㅋㅋㅋ. 오늘 뭔가 좀 꼬였는지 자꾸 뒤집고 싶다 각설하고 문제로 들어가보자 어제 했던 글자 뒤집기와 비슷한데 여기서는 숫자를 뒤집어서 덧셈을 하라는 문제이다. 처음 떠올린 방식은 자바에서는 숫자의 경우 문자열로 뒤집고 숫자로 다시 만들어주는 방식을 많이 취하기 때문에 어제와 같이 배열에다가 넣어주는 것을 생각했었다. 하지만 마지막에 덧셈을 해주어야 하기 때문에 굳이 메모리가 많이 먹는 배열을 선언하기 보다는 수식을 통해 Rev() 함수를 만들어서 덧셈을 하는 방식을 택했다. 알고리즘 생각 1. x,y 입력받기 2. Rev함수 만들기 -숫자를..
-
1/23기록 - 백준 1259Algorithm 2022. 1. 23. 11:12
아침에 날씨가 좀 꿀꿀해서 기분이 상쾌하진 않았지만 매일 아침의 시작을 알리는 작업으로 하기로 한 나와의 약속을 위해 알고리즘 문제를 하나 풀었다. 오늘의 문제는 백준 1259번 펠린드롬수 문제이다. 펠린드롬수란 앞에서 읽어도 뒤에서 읽어도 똑같은 수를 말한다. 파이썬 공부를 할 때 봤던 회문판별이랑 같은 원리였다. 사실 회문판별은 중간을 잘라서 앞뒤를 비교하는 거였는데, 하다 보니 잘 기억이 나지를 않아서 그냥 앞뒤를 비교하는 방식을 택했다. 알고리즘 생각 1. string 문자열 하나를 입력받는다. (숫자 이지만 equals로 비교를 하기위해서는 문자열로 인식시키는 것이 좋다.) 2. equals 메소드를 이용해서 0이 되면 break를 해준다. 3. 입력받은 문자열을 배열의 인덱스로 문자 하나하나를..
-
1/22기록 - 백준 4344Algorithm 2022. 1. 22. 11:24
주말인 만큼 가뿐한 문제 하나 풀어보자는 생각으로 어제와 유사한 평균 문제를 풀어보았다. 결론적으로 생각은 너무 쉽게 했고, 문제를 쭉쭉 풀었는데 답이 계속 이상하게 나와서 의도치 않게 애를 먹은 문제였다. 백준 4344번 평균은 넘겠지 문제이다. 문제가 너무나 간단하기 때문에 읽어보면 바로 이해가 된다. 총 케이스 5개에 대해서 평균이상이 된 사람의 비율을 구하면 된다. 알고리즘 생각 1. 케이스 수를 입력받는다. 2. 배열을 하나 선언하고 입력받을 성적 수를 N으로 두고 N크기의 반복문으로 배열에다 차곡차곡 담아준다. 3. 평균을 구하기 위해 sum과 avg 변수를 선언해서 식을 만들어준다. 4. 평균보다 성적이 높을 경우 count++하는 반복문을 만들어준다. 5. 평균을 넘는 학생 퍼센트는 (co..