반응형

파이썬 45

[이취코] 알고리즘 유형별 기출문제: 그리디 - 2. 곱하기 혹은 더하기 (Python)

2. 곱하기 혹은 더하기 문제 각 자리가 숫자(0부터 9)로만 이루어진 문자열 S가 주어졌을 때, 왼쪽부터 오른쪽으로 하나씩 모든 숫자를 확인하며 숫자 사이에 ‘X’ 혹은 ‘+’ 연산자를 넣어 결과적으로 만들어질 수 있는 가장 큰 수를 구하는 프로그램을 작성하시오. 단, +보다 x를 먼저 계산하는 일반적인 방식과는 달리 모든 연산은 왼쪽에서부터 순서대로 이루어진다고 가정함. 만들어질 수 있는 가장 큰 수는 항상 20억 이하의 정수가 되도록 입력이 주어짐 예시 02984라는 문자열이 주어지면, 만들어질 수 있는 가장 큰 수는 ((((0+2)*9)8)*4)=576임 567이 주어지면 가능한 가장 큰 수는 567=210임 입출력 조건 입력: 첫째 줄에 여러 개의 숫자로 구성된 하나의 문자열 S가 주어짐 (1 ..

[이취코] 알고리즘 유형별 기출문제: 그리디 - 1. 모험가 길드 (Python)

1. 모험가 길드 문제 한 마을에 N명의 모험가가 있다. 모험가 길드에서는 N명의 모험가를 대상으로 ‘공포도’를 측정했는데, ‘공포도’가 높은 모험가는 쉽게 공포를 느껴 위험 상황에서 제대로 대처할 능력이 떨어진다. 모험가 길드장인 동빈이는 모험가 그룹을 안전하게 구성하고자 공포도가 X인 모험가는 반드시 X명 이상으로 구성한 모험가 그룹에 참여해야 여행을 떠날 수 있도록 규정했다. 동빈이는 최대 몇 개의 모험가 그룹을 만들 수 있을지 궁금하다. 동빈이를 위해 N명의 모험가에 대한 정보가 주어졌을 때, 여행을 떠날 수 있는 그룹 수의 최댓값을 구하는 프로그램을 작성하시오. 단, 몇 명의 모험가는 마을에 그대로 남아 있어도 되므로 모든 모험가를 특정 그룹에 넣을 필요는 없음 예시 N=5, 공포도 2 3 1 ..

[리트코드 LeetCode] Search for a Range (Find First and Last Position of Element in Sorted Array) (Python)

Search for a Range (Find First and Last Position of Element in Sorted Array) https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/802/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. l..

[리트코드 LeetCode] Find Peak Element (Python)

Find Peak Element https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/801/ 분류: Top Interview Questions - Medium - Sorting and Searching Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore...

[리트코드 LeetCode] Generate Parentheses (Python)

Generate Parentheses https://leetcode.com/explore/interview/card/top-interview-questions-medium/109/backtracking/794/ 분류: Top Interview Questions - Medium - Backtracking Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문..

[리트코드 LeetCode] Sqrt(x) (Python)

Sqrt(x) https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/819/ 분류: Top Interview Questions - Medium - Math 문제 음이 아닌 정수 x가 주어졌을 때 x의 제곱근을 계산해라. 결과는 가장 가까운 정수로 내림하여 반환 값도 음이 아닌 정수여야 한다. built-in 연산자나 함수를 사용하지 않고 해결해야 한다. type x: int / rtype: int 예시 Example 1: Input: x = 4 Output: 2 Explanation: The square root of 4 is 2, so we return 2. Example 2: Input: x = 8 Out..

[리트코드 LeetCode] Pow(x, n) (Python)

Pow(x, n) https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/818/ 분류: Top Interview Questions - Medium - Math 문제 x의 n승을 계산하는 pow(x, n)을 구현하라. type x: float, type n: int, rtype: float 예시 Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3 Output: 9.26100 Example 3: Input: x = 2.00000, n = -2 Output: 0.25000 Explanation: 2-..

[리트코드 LeetCode] Excel Sheet Column (Python)

Excel Sheet Column https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/817/ 분류: Top Interview Questions - Medium - Math Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 주어진 문자열 columnTi..

[리트코드 LeetCode] Factorial Trailing Zeroes (Python)

Factorial Trailing Zeroes https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/816/ 분류: Top Interview Questions - Medium - Math Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 주어진 정수 n에..

[리트코드 LeetCode] Happy Numebr (Python)

Happy Number https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/815 분류: Top Interview Questions - Medium - Math 문제 주어진 숫자 n이 happy한지 판단하는 알고리즘을 작성하라. happy number는 다음의 과정을 통해 결정된다 아무 양의 정수로 시작하여 숫자를 각 자릿수의 제곱의 합으로 바꿈 숫자가 1이 될 때까지 위의 과정을 반복하라 (1이 된다면 연산을 반복해도 계속 1에 머물 것이고, 1이 되지 않는다면 영원히 1이 없는 사이클이 반복될 것임) 1이 되어 끝나는 숫자는 happy하다. type n: int / rtype: bool 예시 Exampl..

반응형