Advertisement
Guest User

Untitled

a guest
Jul 4th, 2019
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             var list = Console.ReadLine()
  13.                 .Split(' ')
  14.                 .Where(x => !string.IsNullOrWhiteSpace(x))
  15.                 .Select(int.Parse)
  16.                 .ToList();
  17.  
  18.             string input;
  19.  
  20.             while ((input = Console.ReadLine()) != "End")
  21.             {
  22.                 string command = input.Split(" ")[0];
  23.  
  24.                 if (command == "Switch")
  25.                 {
  26.                     int index = int.Parse(input.Split(" ")[1]);
  27.                     if (index >= 0 && index < list.Count)
  28.                     {
  29.                         int number = list[index];
  30.                         list[index] = number - (number * 2);
  31.                     }
  32.                    
  33.                 }
  34.                 else if (command == "Change")
  35.                 {
  36.                     int index = int.Parse(input.Split(" ")[1]);
  37.                     int value = int.Parse(input.Split(" ")[2]);
  38.  
  39.                     if (index >= 0 && index < list.Count)
  40.                     {
  41.                         list[index] = value;
  42.                     }
  43.                 }
  44.                 else if (command == "Sum")
  45.                 {
  46.                     string commandType = input.Split(" ")[1];
  47.                     if (commandType == "Negative")
  48.                     {
  49.                        
  50.                         Console.WriteLine(list.Where(x => x < 0).Sum());
  51.                     }
  52.                     else if (commandType == "Positive")
  53.                     {
  54.                         Console.WriteLine(list.Where(x => x >= 0).Sum());
  55.                     }
  56.                     else if (commandType == "All")
  57.                     {
  58.                         Console.WriteLine(list.Sum());
  59.                     }
  60.                 }
  61.             }
  62.             Console.WriteLine(string.Join(" ", list.Where(x => x >= 0)));
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement