Решаю потихонку задачки...
250namespace SRM438
{
public class UnluckyNumbers
{
public int getCount(int[] luckySet, int n)
{
Array.Sort(luckySet);
int result = 0;
for (int i = 0; i < luckySet.Length - 1; i++)
{
if (luckySet[i] < n & luckySet[i + 1] > n)
{
if (luckySet[i + 1] - 1 - luckySet[i] + 1 > 1)
{
result += (luckySet[i + 1] - n) * (n - luckySet[i]) - 1;
}
}
}
return result;
}
}
}
* This source code was highlighted with
Source Code Highlighter.
Заюзал NUnit v2.5 для тестирования ;-)
[TestFixture]
public class UnluckyNumbersTests
{
[TestCase(new int[] { 1, 7, 14, 10 }, 2,4)]
[TestCase(new int[] { 4, 8, 13, 24, 30 }, 10,5)]
[TestCase(new int[] { 10, 20, 30, 40, 50 }, 30,0)]
[TestCase(new int[] { 3, 7, 12, 18, 25, 100, 33, 1000 }, 59,1065)]
public void getCountTest(int[] luckySet, int n, int expectedResult)
{
UnluckyNumbers unluckyNumbers = new UnluckyNumbers();
int result = unluckyNumbers.getCount(luckySet, n);
Assert.AreEqual(expectedResult, result);
}
}
* This source code was highlighted with
Source Code Highlighter.