Advertisement
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 ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> numbers = Console.ReadLine().Split(' ').ToList();
- List<string> command = new List<string>();
- command.Add("");
- while (command[0] != "print")
- {
- command = Console.ReadLine().Split(' ').ToList();
- if (command[0] == "add")
- {
- numbers.Insert(Convert.ToInt32(command[1]), command[2]);
- }
- else if (command[0] == "addMany")
- {
- int index = Convert.ToInt32(command[1]);
- command.Remove(command[0]);
- command.Remove(command[0]);
- numbers.InsertRange(index, command);
- }
- else if (command[0] == "contains")
- {
- if (numbers.Contains(command[1]))
- {
- for (int i = 0; i < numbers.Count; i++)
- {
- if (numbers[i] == command[1])
- {
- Console.WriteLine(i);
- break;
- }
- }
- }
- else
- {
- Console.WriteLine(-1);
- }
- }
- else if (command[0] == "remove")
- {
- numbers.Remove(numbers[Convert.ToInt32(command[1])]);
- }
- else if (command[0] == "shift") // 0 1 2 3 4 5 6 7 8
- {
- for (int y = 1; y <= Convert.ToInt32(command[1]); y++)
- {
- string numberToAddAtTheEnd = numbers[0];
- numbers.Add(numberToAddAtTheEnd);
- numbers.Remove(numbers[0]);
- }
- }
- else if (command[0] == "sumPairs")
- {
- if (numbers.Count % 2 != 0)
- {
- numbers.Add("0");
- }
- for (int j = numbers.Count - 1; j >= 1; j-=2)
- {
- numbers[j] = Convert.ToString(Convert.ToInt32(numbers[j]) + Convert.ToInt32(numbers[j - 1]));
- numbers.Remove(numbers[j - 1]);
- }
- }
- }
- Console.WriteLine("[{0}]", string.Join(", ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement