Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Exam
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- string[] command = Console.ReadLine().Split().ToArray();
- while (command[0] != "End")
- {
- if (command[0] == "Switch")
- {
- Switch(numbers, command);
- }
- if (command[0] == "Change")
- {
- Change(numbers, command);
- }
- if (command[1] == "Negative")
- {
- Console.WriteLine(numbers.Where(x => x < 0).Sum());
- }
- if (command[1] == "Positive")
- {
- Console.WriteLine(numbers.Where(x => x > 0).Sum());
- }
- if (command[1] == "All")
- {
- Console.WriteLine(numbers.Sum());
- }
- command = Console.ReadLine().Split().ToArray();
- }
- numbers.RemoveAll(x => x < 0);
- Console.WriteLine(string.Join(" ", numbers));
- }
- private static void Change(List<int> numbers, string[] command)
- {
- int index = int.Parse(command[1]);
- int number = int.Parse(command[2]);
- if (index >= 0 && index < numbers.Count)
- {
- numbers[index] = number;
- }
- }
- private static void Switch(List<int> numbers, string[] command)
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < numbers.Count)
- {
- numbers[index] *= -1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment