I want to show you task from Russian EGE exam
Given an array containing positive integers that do not exceed 15000. Find the number of even elements in the array that are not multiples of 3, replace all odd elements that are multiples of 3 with this number, and output the modified array. For example, for a source array of five elements 20, 89, 27, 92, 48, the program must output numbers 20, 89, 2, 92, 48.
using System;
public class RussianExam
{
public static int[] ExamTask(int[] array)
{
int count = 0;
for(int i = 0; i < array.Length; i++)
{
if (array[i] % 3 != 0 && array[i] % 2 == 0) count++;
}
for (int i = 0; i < array.Length; i++)
{
if (array[i] % 3 == 0 && array[i] % 2 != 0) array[i] = count;
}
return array;
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
int[] expected = new int[] { 20, 89, 2, 92, 48 };
int[] input = new int[] { 20, 89, 27, 92, 48 };
Assert.AreEqual(expected, RussianExam.ExamTask(input));
}
}
}