Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ArrayModifier
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "end")
- {
- string [] commandArray = command.Split();
- if (commandArray[0] == "swap")
- {
- int index1 = int.Parse(commandArray[1]);
- int index2 = int.Parse(commandArray[2]);
- if(index1>=0 && index1<=numbers.Count-1 && index2 >= 0 && index2 <= numbers.Count - 1 && index1!=index2)
- {
- int firstElement = numbers[index1];
- int secondElement = numbers[index2];
- numbers[index1] = secondElement;
- numbers[index2] = firstElement;
- }
- }
- else if (commandArray[0] == "multiply")
- {
- int index1 = int.Parse(commandArray[1]);
- int index2 = int.Parse(commandArray[2]);
- if (index1 >= 0 && index1 <= numbers.Count - 1 && index2 >= 0 && index2 <= numbers.Count - 1 && index1 != index2)
- {
- int firstElement = numbers[index1];
- int secondElement = numbers[index2];
- numbers[index1] = firstElement * secondElement;
- }
- }
- else if (commandArray[0] == "decrease")
- {
- for (int i = 0; i < numbers.Count; i++)
- {
- numbers[i] = numbers[i] - 1;
- }
- }
- }
- Console.WriteLine(string.Join(", ",numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement