Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace P02.ArrayModifier
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- long[] elements = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(long.Parse)
- .ToArray();
- long temp = 0;
- string command = Console.ReadLine();
- while(command != "end")
- {
- string[] cmdArgs = command.Split();
- string action = cmdArgs[0];
- int indexOne = int.Parse(cmdArgs[1]);
- int indexTwo = int.Parse(cmdArgs[2]);
- if(action == "swap")
- {
- temp = elements[indexOne];
- elements[indexOne] = elements[indexTwo];
- elements[indexTwo] = temp;
- }
- else if(action == "multiply")
- {
- elements[indexOne] = elements[indexOne] * elements[indexTwo];
- }
- else if(action == "decrease")
- {
- for (int i = 0; i < elements.Length; i++)
- {
- elements[i]--;
- }
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(", ", elements));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement