Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Number_Array_MidExam_30thOfJune2019
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] input = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- string command = Console.ReadLine();
- while (command != "End")
- {
- string[] splitedCommand = command.Split(" ");
- string commandOne = splitedCommand[0];
- int sumNegative = 0;
- int sumPositive = 0;
- int sumOfAll = 0;
- if (commandOne == "Switch")
- {
- int index = int.Parse(splitedCommand[1]);
- for (int i = 0; i < input.Length; i++)
- {
- if (i == index)
- {
- input[i] *= -1;
- }
- }
- }
- else if (commandOne == "Change")
- {
- int index = int.Parse(splitedCommand[1]);
- int value = int.Parse(splitedCommand[2]);
- for (int i = 0; i < input.Length; i++)
- {
- if (i == index)
- {
- input[i] = value;
- }
- }
- }
- else if (commandOne == "Sum")
- {
- string secretCommand = splitedCommand[1];
- if (secretCommand == "Negative")
- {
- // int sumNegative = 0;
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] < 0)
- {
- sumNegative += input[i];
- }
- }
- Console.WriteLine(sumNegative);
- }
- else if (secretCommand == "Positive")
- {
- // int sumPositive = 0;
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] >= 0)
- {
- sumPositive += input[i];
- }
- }
- Console.WriteLine(sumPositive);
- }
- else if (secretCommand == "All")
- {
- // int sumOfAll = 0;
- for (int i = 0; i < input.Length; i++)
- {
- sumOfAll += input[i];
- }
- Console.WriteLine(sumOfAll);
- }
- }
- command = Console.ReadLine();
- }
- if (command == "End")
- {
- //for (int i = 0; i < input.Length; i++)
- //{
- // Console.WriteLine(string.Join(" ", input[i]+ " "));
- //}
- foreach (int num in input)
- {
- if (num >= 0)
- {
- Console.Write(num + " ");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment