Skip to content

Instantly share code, notes, and snippets.

@unilecs
Last active January 24, 2025 05:15
Show Gist options
  • Save unilecs/69dff66f69bf3b70780ad4291b1b66bc to your computer and use it in GitHub Desktop.
Save unilecs/69dff66f69bf3b70780ad4291b1b66bc to your computer and use it in GitHub Desktop.
Задача: Разминировать бомбу
using System;
public class Program
{
public static int[] DefuseBomb(int[] arr, int k) {
int N = arr.Length;
var res = new int[N];
if (k == 0) {
return res;
}
for (int i = 0; i < N; i++)
{
if (k > 0) {
for (int j = i + 1; j < i + k + 1; j++) {
res[i] += arr[j % N];
}
}
else
{
for (int j = i - Math.Abs(k); j < i; j++) {
res[i] += arr[(j + N) % N];
}
}
}
return res;
}
public static void Main()
{
Console.WriteLine("UniLecs");
// tests
Console.WriteLine(string.Join(", ", DefuseBomb(new int[] { 5, 7, 1, 4 }, 3))); // [ 12, 10, 16, 13 ]
Console.WriteLine(string.Join(", ", DefuseBomb(new int[] { 2, 4, 9, 3 }, -2))); // [ 12, 5, 6, 13 ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment