-
-
Save astambi/a842ae15a31408aab7c97f223801a8fd to your computer and use it in GitHub Desktop.
Array Modifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Array_Modifier | |
{ | |
class Array_Modifier | |
{ | |
static void Main(string[] args) | |
{ | |
long[] numbers = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); | |
string inputOver = "end"; | |
string input = ""; | |
while ( (input = Console.ReadLine()) != inputOver) | |
{ | |
string[] inputDetails = input.Split(' ').ToArray(); | |
string command = inputDetails[0]; | |
if (command == "swap" || command == "multiply") | |
{ | |
int index1 = int.Parse(inputDetails[1]); | |
int index2 = int.Parse(inputDetails[2]); | |
switch (command) | |
{ | |
case "swap": | |
long tempElement = numbers[index1]; | |
numbers[index1] = numbers[index2]; | |
numbers[index2] = tempElement; | |
break; | |
case "multiply": | |
numbers[index1] *= numbers[index2]; | |
break; | |
} | |
} | |
else if(command == "decrease") | |
{ | |
for (int i = 0; i < numbers.Length; i++) | |
numbers[i] -= 1; | |
} | |
} | |
Console.WriteLine(string.Join(", ", numbers)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment