private static void ex3() { int select = 0; while (select > 2 || select < 1) { Console.Write("1 first method, 2 second method"); select = int.Parse(Console.ReadLine()); } string people; using (StreamReader file = new StreamReader(path3)) people = file.ReadToEnd(); string[] tmp = people.Split(new char[] { ' ' }); Console.Write("Запишите считалочку: "); string[] count = Console.ReadLine().Split(new char[] { ' ', ',', '-', '.', '?', ';', ':', '"' }, StringSplitOptions.RemoveEmptyEntries); Console.Write("Выбирите с какого участника начать от 1 до {0}: ", tmp.Length); int start = 0; while (start > tmp.Length || start < 1) { start = int.Parse(Console.ReadLine()); } if (select == 1) { CircularLinkedList <string> users = new CircularLinkedList <string>(); foreach (string s in tmp) { users.Add(s); } users.Counting(start, count.Length); } else if (select == 2) { Console.WriteLine("Победитель: " + tmp[(count.Length % tmp.Length) - 2 + start]); } Console.ReadKey(); }
public static void Execute() { int select = 0; while (select > 2 || select < 1) { Console.Write("Write 1 to solve it by using circular linked list and 2 to solve it without no additional data structures: "); select = int.Parse(Console.ReadLine()); } string people = String.Empty; using (StreamReader file = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "people.txt"))) people = file.ReadToEnd(); string[] participants = people.Split(new char[] { ' ' }); Console.Write("Write counting sentence: "); string[] counting = Console.ReadLine().Split(new char[] { ' ', ',', '-', '.', '?', ';', ':', '"' }, StringSplitOptions.RemoveEmptyEntries); Console.Write("Choose which person to start with from 1 to {0}: ", participants.Length); int start = 0; while (start > participants.Length || start < 1) { start = int.Parse(Console.ReadLine()); } if (select == 1) { CircularLinkedList <string> users = new CircularLinkedList <string>(); foreach (string s in participants) { users.Add(s); } users.Counting(start, counting.Length); } else if (select == 2) { Console.WriteLine("The winner is: " + participants[(counting.Length % participants.Length) - 2 + start]); } }