Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace try1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- string input = Console.ReadLine();
- while (input != "end")
- {
- string[] tockens = input.Split().ToArray();
- if (tockens[0] == "exchange")
- {
- int index = int.Parse(tockens[1]);
- if (index > -1 && index < arr.Length)
- {
- for (int i = 0; i < index + 1; i++)
- {
- int first = arr[0];
- for (int j = 1; j < arr.Length; j++)
- {
- arr[j - 1] = arr[j];
- }
- arr[arr.Length - 1] = first;
- }
- }
- else
- {
- Console.WriteLine("Invalid index");
- }
- }
- int evenCount = 0;
- int oddCount = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 == 0)
- {
- evenCount++;
- }
- else
- {
- oddCount++;
- }
- }
- if (tockens[0] == "max")
- {
- if (tockens[1] == "even")
- {
- if (evenCount > 0)
- {
- int indexMinMax = 0;
- int curr = 0;
- int maxEven = int.MinValue;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 == 0)
- {
- if (arr[i] > maxEven)
- {
- maxEven = arr[i];
- indexMinMax = i;
- curr = maxEven;
- }
- if (curr == arr[i])
- {
- indexMinMax = i;
- }
- }
- }
- Console.WriteLine(indexMinMax);
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- if (tockens[1] == "odd")
- {
- if (oddCount > 0)
- {
- int indexMinMax = 0;
- int curr = 0;
- int maxOdd = int.MinValue;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 != 0)
- {
- if (arr[i] > maxOdd)
- {
- maxOdd = arr[i];
- indexMinMax = i;
- curr = maxOdd;
- }
- if (curr == arr[i])
- {
- indexMinMax = i;
- }
- }
- }
- Console.WriteLine(indexMinMax);
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- }
- else if (tockens[0] == "min")
- {
- if (tockens[1] == "even")
- {
- if (evenCount > 0)
- {
- int indexMinMax = 0;
- int curr = 0;
- int minEven = int.MaxValue;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 == 0)
- {
- if (arr[i] < minEven)
- {
- minEven = arr[i];
- indexMinMax = i;
- curr = minEven;
- }
- if (curr == arr[i])
- {
- indexMinMax = i;
- }
- }
- }
- Console.WriteLine(indexMinMax);
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- if (tockens[1] == "odd")
- {
- if (evenCount > 0)
- {
- int indexMinMax = 0;
- int curr = 0;
- int minOdd = int.MaxValue;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 != 0)
- {
- if (arr[i] < minOdd)
- {
- minOdd = arr[i];
- indexMinMax = i;
- curr = minOdd;
- }
- if (curr == arr[i])
- {
- indexMinMax = i;
- }
- }
- }
- Console.WriteLine(indexMinMax);
- }
- else
- {
- Console.WriteLine("No matches");
- }
- }
- }
- else if (tockens[0] == "first")
- {
- int count = int.Parse(tockens[1]);
- if (count > arr.Length)
- {
- Console.WriteLine("Invalid count");
- }
- else
- {
- if (tockens[2] == "even")
- {
- if (evenCount == 0)
- {
- Console.WriteLine("[]");
- }
- else
- {
- if (evenCount < count)
- {
- count = evenCount;
- }
- int[] toPrint = new int[count];
- int toPrintCounter = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 == 0)
- {
- toPrint[toPrintCounter] += arr[i];
- toPrintCounter++;
- }
- if (toPrintCounter == count)
- {
- break;
- }
- }
- Console.WriteLine($"[{string.Join(", ", toPrint)}]");
- }
- }
- else if (tockens[2] == "odd")
- {
- if (oddCount == 0)
- {
- Console.WriteLine("[]");
- }
- else
- {
- if (oddCount < count)
- {
- count = oddCount;
- }
- int[] toPrint = new int[count];
- int toPrintCounter = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 != 0)
- {
- toPrint[toPrintCounter] += arr[i];
- toPrintCounter++;
- }
- if (toPrintCounter == count)
- {
- break;
- }
- }
- Console.WriteLine($"[{string.Join(", ", toPrint)}]");
- }
- }
- }
- }
- else if (tockens[0] == "last")
- {
- int count = int.Parse(tockens[1]);
- if (count > arr.Length)
- {
- Console.WriteLine("Invalid count");
- }
- else
- {
- if (tockens[2] == "even")
- {
- if (evenCount == 0)
- {
- Console.WriteLine("[]");
- }
- else
- {
- if (evenCount < count)
- {
- count = evenCount;
- }
- int[] toPrint = new int[count];
- int toPrintCounter = 0;
- for (int i = arr.Length-1; i >= 0; i--)
- {
- if (arr[i] % 2 == 0)
- {
- toPrint[toPrintCounter] += arr[i];
- toPrintCounter++;
- }
- if (toPrintCounter == count)
- {
- break;
- }
- }
- Console.WriteLine($"[{string.Join(", ", toPrint.Reverse())}]"); //here
- }
- }
- else if (tockens[2] == "odd")
- {
- if (oddCount == 0)
- {
- Console.WriteLine("[]");
- }
- else
- {
- if (oddCount < count)
- {
- count = oddCount;
- }
- int[] toPrint = new int[count];
- int toPrintCounter = 0;
- for (int i = arr.Length-1; i >= 0; i--)
- {
- if (arr[i] % 2 != 0)
- {
- toPrint[toPrintCounter] += arr[i];
- toPrintCounter++;
- }
- if (toPrintCounter == count)
- {
- break;
- }
- }
- Console.WriteLine($"[{string.Join(", ", toPrint.Reverse())}]"); //here
- }
- }
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"[{string.Join(", ", arr)}]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement