문제: app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query/
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 i = 0; i < S.Length; i++)
{
arrayA[i + 1] = a;
arrayC[i + 1] = c;
arrayG[i + 1] = g;
switch (S.Substring(i, 1))
{
case "A":
a = a + 1;
arrayA[i + 1] = a;
break;
case "C":
c = c + 1;
arrayC[i + 1] = c;
break;
case "G":
g = g + 1;
arrayG[i + 1] = g;
break;
}
}
for (int i = 0; i < P.Length; i++)
{
if (arrayA[P[i]] < arrayA[Q[i] + 1])
result[i] = 1;
else if (arrayC[P[i]] < arrayC[Q[i] + 1])
result[i] = 2;
else if (arrayG[P[i]] < arrayG[Q[i] + 1])
result[i] = 3;
else
result[i] = 4;
}
return result;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson5. PassingCars (C#) (0) | 2020.11.17 |
---|---|
[Codility] Lesson5. MinAvgTwoSlice (C#) (0) | 2020.11.17 |
[Codility] Lesson5. CountDiv (C#) (0) | 2020.11.17 |
[Codility] Lesson4. PermCheck (C#) (0) | 2020.11.17 |
[Codility] Lesson4. MissingInteger (C#) (0) | 2020.11.17 |