본문 바로가기

공부하자/Codility

(35)
[Codility] Lesson7. Brackets (C#) 문제: app.codility.com/programmers/lessons/7-stacks_and_queues/brackets/ Brackets coding task - Learn to Code - Codility Determine whether a given string of parentheses (multiple types) is properly nested. app.codility.com char[] ArrayS = S.ToCharArray(); Stack StackS = new Stack(); for (int i = 0; i < ArrayS.Length; i++) { if (ArrayS[i].Equals('[') || ArrayS[i].Equals('{') || ArrayS[i].Equals('('..
[Codility] Lesson6. Triangle (C#) 문제: app.codility.com/programmers/lessons/6-sorting/triangle/ Triangle coding task - Learn to Code - Codility Determine whether a triangle can be built from a given set of edges. app.codility.com int result = 0; List ListA = new List(A); ListA.Sort(); if (ListA.Count < 3) return 0; for (int i = 2; i < ListA.Count; i++) { if (ListA[i] < 1 || ListA[i - 1] < 1 || ListA[i - 2] < 1) continue; if (List..
[Codility] Lesson6. NumberOfDiscIntersections (C#) 문제: app.codility.com/programmers/lessons/6-sorting/number_of_disc_intersections/ NumberOfDiscIntersections coding task - Learn to Code - Codility Compute the number of intersections in a sequence of discs. app.codility.com int result = 0; int[] start = new int[A.Length]; int[] end = new int[A.Length]; int t = A.Length - 1; for (int i = 0; i A[i] ? i - A[i] : 0; int..
[Codility] Lesson6. MaxProductOfThree (C#) 문제: app.codility.com/programmers/lessons/6-sorting/max_product_of_three/ MaxProductOfThree coding task - Learn to Code - Codility Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R). app.codility.com List ListA = new List(A); ListA.Sort(); if (ListA[A.Length - 1] < 0) return ListA[A.Length - 1] * ListA[A.Length - 2] * ListA[A.Length - 3]; int pre = ListA[0] * ListA[1]; int post = ListA[A.Lengt..
[Codility] Lesson6. Distinct (C#) 문제: app.codility.com/programmers/lessons/6-sorting/distinct/ Distinct coding task - Learn to Code - Codility Compute number of distinct values in an array. app.codility.com if (A.Length == 0) return 0; List ListA = new List(A); ListA.Sort(); int result = 1; int index = ListA[0]; for (int i = 0; i < ListA.Count; i++) { if (ListA[i] != index) { result = result + 1; index = ListA[i]; } } return res..
[Codility] Lesson5. PassingCars (C#) 문제: app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/ PassingCars coding task - Learn to Code - Codility Count the number of passing cars on the road. app.codility.com int result = 0; int zero = 0; for (int i = 0; i 1000000000) result = -1; return result;
[Codility] Lesson5. MinAvgTwoSlice (C#) 문제: app.codility.com/programmers/lessons/5-prefix_sums/min_avg_two_slice/ MinAvgTwoSlice coding task - Learn to Code - Codility Find the minimal average of any slice containing at least two elements. app.codility.com double minAvg = (A[0] + A[1]) / 2.0; int result = 0; for (int i = 2; i avg) { minAvg = avg; result =..
[Codility] Lesson5. GenomicRangeQuery (C#) 문제: app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query/ GenomicRangeQuery coding task - Learn to Code - Codility Find the minimal nucleotide from a range of sequence DNA. app.codility.com int[] arrayA = new int[S.Length + 1]; int[] arrayC = new int[S.Length + 1]; int[] arrayG = new int[S.Length + 1]; int a = 0; int c = 0; int g = 0; int[] result = new int[P.Length]; for (int ..