Created
September 2, 2024 18:05
-
-
Save unilecs/94f15271fe9cc51cd6ee3df1e1e1def5 to your computer and use it in GitHub Desktop.
Задача: Горячая картошка
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static int HotPotato(int n, int time) { | |
int full = time / (n - 1); | |
int extra = time % (n - 1); | |
int direction = full % 2 == 0 ? 1 : -1; | |
return direction == 1 ? extra + 1 : n - extra; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
// tests | |
Console.WriteLine(HotPotato(4, 5).ToString()); // 2 | |
Console.WriteLine(HotPotato(3, 2).ToString()); // 3 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment