본문 바로가기
728x90
반응형

알고리즘문제풀이21

[Codility] Lesson10 - Prime and Composite numbers : CountFactors (c++) Problem A positive integer D is a factor of a positive integer N if there exists an integer M such that N = D * M. For example, 6 is a factor of 24, because M = 4 satisfies the above condition (24 = 6 * 4). Write a function: int solution(int N); that, given a positive integer N, returns the number of its factors. For example, given N = 24, the function should return 8, because 24 has 8 factors, .. 2021. 1. 12.
[Codility] Lesson9 - Maximum Slice Problem: MaxSliceSum (c++) Problem A non-empty array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P ≤ Q < N, is called a slice of array A. The sum of a slice (P, Q) is the total of A[P] + A[P+1] + ... + A[Q]. Write a function: int solution(vector &A); that, given an array A consisting of N integers, returns the maximum sum of any slice of A. For example, given array A such that: A[0] = 3 A.. 2021. 1. 10.
[Codility] Lesson9 - Maximum slice problem : MaxProfit Problem An array A consisting of N integers is given. It contains daily prices of a stock share for a period of N consecutive days. If a single share was bought on day P and sold on day Q, where 0 ≤ P ≤ Q < N, then the profit of such transaction is equal to A[Q] − A[P], provided that A[Q] ≥ A[P]. Otherwise, the transaction brings loss of A[P] − A[Q]. For example, consider the following array A c.. 2021. 1. 8.
[Codility] Lesson8 - Leader : EquiLeader (c++) Problem A non-empty array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A. An equi leader is an index S such that 0 ≤ S < N − 1 and two sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N − 1] have leaders of the same value. For example, given array A such that: A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4.. 2021. 1. 7.
728x90
반응형