Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Numerics;
- namespace _02_SecondExercise
- {
- class KaminoFactory
- {
- static void Main(string[] args)
- {
- List<int> arr = Console.ReadLine().Split().Select(int.Parse).ToList();
- string input = Console.ReadLine();
- while (input!="end")
- {
- string[] tokens = input.Split().ToArray();
- string command = tokens[0];
- if (command== "exchange")
- {
- int index = int.Parse(tokens[1]);
- if (index<arr.Count)
- {
- index++;
- var temp = arr.Take(index);
- arr = arr.Skip(index).ToList();
- arr = arr.Concat(temp).ToList();
- }
- else
- {
- Console.WriteLine("Invalid index");
- }
- }
- if (command=="max")
- {
- string evenOdd = tokens[1];
- if (evenOdd == "even")
- {
- int max = int.MinValue;
- int indexEven =-1;
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 == 0)
- {
- if (arr[i] >= max)
- {
- max = arr[i];
- indexEven = i;
- }
- }
- }
- if (indexEven == -1)
- {
- Console.WriteLine("No matches");
- }
- else { Console.WriteLine(indexEven); }
- }
- else if (evenOdd == "odd")
- {
- int max = int.MinValue;
- int indexOdd = -1;
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 != 0)
- {
- if (arr[i] >= max)
- {
- max = arr[i];
- indexOdd = i;
- }
- }
- }
- if (indexOdd == -1)
- {
- Console.WriteLine("No matches");
- }
- else { Console.WriteLine(indexOdd); }
- }
- }
- if (command == "min")
- {
- string evenOdd = tokens[1];
- if (evenOdd == "even")
- {
- int min = int.MaxValue;
- int indexEven = -1;
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 == 0)
- {
- if (arr[i] <= min)
- {
- min = arr[i];
- indexEven = i;
- }
- }
- }
- if (indexEven == -1)
- {
- Console.WriteLine("No matches");
- }
- else { Console.WriteLine(indexEven); }
- }
- else if (evenOdd == "odd")
- {
- int min = int.MaxValue;
- int indexOdd = -1;
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 != 0)
- {
- if (arr[i] <= min)
- {
- min = arr[i];
- indexOdd = i;
- }
- }
- }
- if (indexOdd == -1)
- {
- Console.WriteLine("No matches");
- }
- else { Console.WriteLine(indexOdd); }
- }
- }
- if (command =="first")
- {
- int count = int.Parse(tokens[1]);
- if (count > arr.Count)
- {
- Console.WriteLine("Invalid count");
- }
- else
- {
- string seccommand = tokens[2];
- List<int> firstEven = new List<int>();
- List<int> firstOdd = new List<int>();
- if (seccommand == "even")
- {
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 == 0)
- {
- firstEven.Add(arr[i]);
- }
- }
- firstEven = firstEven.Take(count).ToList();
- Console.WriteLine($"[" + string.Join(", ", firstEven) + "]");
- }
- else if (seccommand == "odd")
- {
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 != 0)
- {
- firstOdd.Add(arr[i]);
- }
- }
- firstOdd = firstOdd.Take(count).ToList();
- Console.WriteLine($"[" + string.Join(", ", firstOdd) + "]");
- }
- }
- }
- if (command =="last")
- {
- int count = int.Parse(tokens[1]);
- if (count > arr.Count)
- {
- Console.WriteLine("Invalid count");
- }
- else
- {
- string seccommand = tokens[2];
- List<int> lastEven = new List<int>();
- List<int> lastOdd = new List<int>();
- if (seccommand == "even")
- {
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 == 0)
- {
- lastEven.Add(arr[i]);
- }
- }
- lastEven = lastEven.Take(count).ToList();
- Console.WriteLine($"[" + string.Join(", ", lastEven) + "]");
- }
- else if (seccommand == "odd")
- {
- for (int i = 0; i < arr.Count; i++)
- {
- if (arr[i] % 2 != 0)
- {
- lastOdd.Add(arr[i]);
- }
- }
- lastEven = lastEven.Take(count).ToList();
- Console.WriteLine($"[" + string.Join(", ", lastOdd) + "]");
- }
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine("["+string.Join(", ",arr)+"]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement