Skip to content

Instantly share code, notes, and snippets.

@astambi
Created May 12, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astambi/a842ae15a31408aab7c97f223801a8fd to your computer and use it in GitHub Desktop.
Save astambi/a842ae15a31408aab7c97f223801a8fd to your computer and use it in GitHub Desktop.
Array Modifier
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