Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace task_27
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> list = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(s => int.Parse(s))
- .ToList();
- for (int i = 0; ; i++)
- {
- List<string> input = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- if (input.Contains("add") && !input.Contains("addMany"))
- {
- int index = int.Parse(input[1]);
- int element = int.Parse(input[2]);
- list.Add(list[list.Count - 1]);
- for (int j = list.Count - 1; j > index; j--)
- {
- list[j] = list[j - 1];
- }
- list[index] = element;
- }
- if (input.Contains("addMany"))
- {
- int index = int.Parse(input[1]);
- int[] element = new int[input.Count - 2];
- for (int j = 0; j < element.Length; j++)
- {
- element[j] = int.Parse(input[j + 2]);
- }
- for (int j = element.Length; j > 0; j--)
- {
- list.Add(0);
- }
- for (int j = list.Count - 1; j >= index + element.Length; j--)
- {
- list[j] = list[j - element.Length];
- }
- int k = 0;
- for (int j = index; j < index + element.Length; j++, k++)
- {
- list[j] = element[k];
- }
- }
- if (input.Contains("contains"))
- {
- int element = int.Parse(input[1]);
- bool exist = false;
- for (int j = 0; j < list.Count; j++)
- {
- if (list[j] == element)
- {
- exist = true;
- Console.WriteLine(j);
- break;
- }
- }
- if (exist == false)
- {
- Console.WriteLine(-1);
- }
- }
- if (input.Contains("remove"))
- {
- int index = int.Parse(input[1]);
- list.RemoveAt(index);
- }
- if (input.Contains("shift"))
- {
- int position = int.Parse(input[1]);
- for (int j = 0; j < position; j++)
- {
- list.Add(0);
- }
- for (int j = 0; j < position; j++)
- {
- list[j + list.Count - position] = list[j];
- }
- list.RemoveRange(0, position);
- }
- if (input.Contains("sumPairs"))
- {
- if (list.Count % 2 != 0)
- {
- list.Add(0);
- }
- for (int j = 0; j < list.Count; j += 2)
- {
- list[j] = list[j] + list[j + 1];
- }
- for (int j = list.Count - 1; j > 0; j -= 2)
- {
- list.RemoveAt(j);
- }
- }
- if (input.Contains("print"))
- {
- Console.WriteLine("[" + string.Join(", ", list) + "]");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment