전체 글
-
[프로그래머스] 모음사전 c++Coding Test/programmers 2022. 10. 11. 15:26
문제 설명 사전에 알파벳 모음 'A', 'E', 'I', 'O', 'U'만을 사용하여 만들 수 있는, 길이 5 이하의 모든 단어가 수록되어 있습니다. 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA"이며, 마지막 단어는 "UUUUU"입니다. 단어 하나 word가 매개변수로 주어질 때, 이 단어가 사전에서 몇 번째 단어인지 return 하도록 solution 함수를 완성해주세요. 제한 사항 word의 길이는 1 이상 5 이하입니다. word는 알파벳 대문자 'A', 'E', 'I', 'O', 'U'로만 이루어져 있습니다. 입출력 예 word result "AAAAE" 6 "AAAE" 10 "I" 1563 "EIO" 1189 풀이 #include #include using namespace std; s..
-
[프로그래머스] 할인 행사 c++Coding Test/programmers 2022. 10. 11. 14:03
문제 설명 XYZ 마트는 일정한 금액을 지불하면 10일 동안 회원 자격을 부여합니다. XYZ 마트에서는 회원을 대상으로 매일 한 가지 제품을 할인하는 행사를 합니다. 할인하는 제품은 하루에 하나씩만 구매할 수 있습니다. 알뜰한 정현이는 자신이 원하는 제품과 수량이 할인하는 날짜와 10일 연속으로 일치할 경우에 맞춰서 회원가입을 하려 합니다. 예를 들어, 정현이가 원하는 제품이 바나나 3개, 사과 2개, 쌀 2개, 돼지고기 2개, 냄비 1개이며, XYZ 마트에서 15일간 회원을 대상으로 할인하는 제품이 날짜 순서대로 치킨, 사과, 사과, 바나나, 쌀, 사과, 돼지고기, 바나나, 돼지고기, 쌀, 냄비, 바나나, 사과, 바나나인 경우에 대해 알아봅시다. 첫째 날부터 열흘 간에는 냄비가 할인하지 않기 때문에 첫..
-
[LeetCode] 1672. Richest Customer Wealth c++Coding Test/LeetCode 2022. 10. 10. 16:43
문제 You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth. Input: accounts = [[1,2,3],[3,2,1]] Output..
-
[LeetCode] 1470. Shuffle the Array c+Coding Test/LeetCode 2022. 10. 10. 16:31
문제 Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. Return the array in the form [x1,y1,x2,y2,...,xn,yn]. Input: nums = [2,5,1,3,4,7], n = 3 Output: [2,3,5,4,1,7] Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7]. 문제 해결 class Solution { public: vector shuffle(vector& nums, int n) { vector answer; for(int i = 0; i < n; i+..
-
[LeetCode] 2011. Final Value of Variable After Performing Operations c++Coding Test/LeetCode 2022. 10. 10. 16:06
문제 There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decrements the value of the variable X by 1. Initially, the value of X is 0. Given an array of strings operations containing a list of operations, return the final value of X after performing all the operations. Input: operations = ["--X","X++","X+..
-
[LeetCode] 35. Search Insert Position c++Coding Test/LeetCode 2022. 10. 10. 13:41
문제 Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Input: nums = [1,3,5,6], target = 5 Output: 2 배열 원소 중 target과 같은 값이 있다면 해당 index 구하고, 없다면 오름차순인 배열에 위치시킬 index를 구하는 문제이다. 문제 해결 이 문제를 해결하기 위해 lower_bound 함수에..
-
[LeetCode] 1480. Running Sum of 1d Array c++Coding Test/LeetCode 2022. 10. 10. 13:20
문제 Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. 문제 해결 class Solution { public: vector runningSum(vector& nums) { int len = nums.size(); vector answer(len, 0); answer[0] = nums[0]; for(int i = 1; ..