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 Problem_2.Array_Modifier
- {
- class Program
- {
- static void Main(string[] args)
- {
- long[] numbers = Console.ReadLine().Split().Select(long.Parse).ToArray();
- string[] commands = Console.ReadLine().Split().ToArray();
- while (commands[0] != "end")
- {
- string command = commands[0];
- int index1 = 0;
- int index2 = 0;
- if (commands.Length > 1)
- {
- index1 = int.Parse(commands[1]);
- index2 = int.Parse(commands[2]);
- }
- if (command == "swap") swap(numbers, index1, index2);
- else if (command == "multiply") multiply(numbers, index1, index2);
- else if (command == "decrease") decrease(numbers);
- commands = Console.ReadLine().Split().ToArray();
- }
- Console.WriteLine(string.Join(", ", numbers));
- }
- private static void decrease(long[] numbers)
- {
- for (int num = 0; num < numbers.Length; num++)
- {
- numbers[num] = numbers[num] - 1;
- }
- }
- private static void multiply(long[] numbers, int index1, int index2)
- {
- long temp = numbers[index1] * numbers[index2];
- numbers[index1] = temp;
- }
- private static void swap(long[] numbers, int index1, int index2)
- {
- long temp1 = numbers[index1];
- long temp2 = numbers[index2];
- numbers[index1] = temp2;
- numbers[index2] = temp1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement