문제: app.codility.com/programmers/lessons/11-sieve_of_eratosthenes/count_non_divisible/
CountNonDivisible coding task - Learn to Code - Codility
Calculate the number of elements of an array that are not divisors of each element.
app.codility.com
결과: 66%.. 다시 풀자..
Dictionary<int, int> listA = new Dictionary<int, int>();
for (int i = 0; i < A.Length; i++)
{
if (!listA.ContainsKey(A[i]))
{
int count = 0;
for (int j = 0; j < A.Length; j++)
{
if (i != j && A[i] % A[j] != 0)
count++;
}
listA.Add(A[i], count);
}
}
int[] result = new int[A.Length];
for (int i = 0; i < A.Length; i++)
{
listA.TryGetValue(A[i], out result[i]);
}
return result;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson12. ChocolatesByNumbers (C#) (0) | 2020.11.27 |
---|---|
[Codility] Lesson11. CountSemiprimes (C#) (0) | 2020.11.27 |
[Codility] Lesson10. Peaks (C#) (0) | 2020.11.27 |
[Codility] Lesson10. MinPerimeterRectangle (C#) (0) | 2020.11.27 |
[Codility] Lesson10. Flags (C#) (0) | 2020.11.20 |