Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Threading.Channels;
- namespace _3._Memory_game
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> sequence = Console.ReadLine().Split().ToList();
- int moves = 0;
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end")
- {
- break;
- }
- moves++;
- int[] indexes = command.Split().Select(int.Parse).ToArray();
- int firstIndex = indexes[0];
- int secondIndex = indexes[1];
- if (indexes[0] < indexes[1])
- {
- firstIndex = indexes[1];
- secondIndex = indexes[0];
- }
- if (firstIndex == secondIndex || firstIndex < 0 || secondIndex < 0 || secondIndex >= sequence.Count ||
- firstIndex >= sequence.Count)
- {
- Console.WriteLine("Invalid input! Adding additional elements to the board");
- //add additional elements
- int middle = sequence.Count / 2;
- sequence.Insert(middle, $"-{moves}a");
- sequence.Insert(middle + 1, $"-{moves}a");
- }
- else
- {
- if (sequence[firstIndex] == sequence[secondIndex])
- {
- Console.WriteLine($"Congrats! You have found matching elements - {sequence[firstIndex]}!");
- sequence.RemoveAt(firstIndex);
- sequence.RemoveAt(secondIndex);
- }
- else
- {
- Console.WriteLine("Try again!");
- continue;
- }
- if (sequence.Count == 0)
- {
- Console.WriteLine($"You have won in {moves} turns!");
- return;
- }
- }
- }
- if (sequence.Count > 0)
- {
- Console.WriteLine("Sorry you lose :(");
- Console.WriteLine(string.Join(" ", sequence));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement