Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Second_attempt
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> friends = Console.ReadLine().Split(", ").ToList();
  12.  
  13.             string input = null;
  14.  
  15.             while ((input = Console.ReadLine()) != "Report")
  16.  
  17.             {
  18.                 string[] command = input.Split().ToArray();
  19.                 string action = command[0];
  20.  
  21.                 switch (action)
  22.                 {
  23.                     case "Blacklist":
  24.                         friends = Blacklist(friends, command).ToList();
  25.                         //  Console.WriteLine(String.Join(" ",friends));
  26.                         break;
  27.                     case "Error":
  28.                         friends = Error(friends, command);
  29.                         // Console.WriteLine(String.Join(" ", friends));
  30.                         break;
  31.  
  32.                     case "Change":
  33.                         friends = Change(friends, command);
  34.                         // Console.WriteLine(String.Join(" ", friends));
  35.                         break;
  36.                 }
  37.  
  38.             }
  39.             int countBlacklist = 0;
  40.             int countLost = 0;
  41.  
  42.  
  43.             foreach (string friend in friends)
  44.             {
  45.                 if (friend == "Blacklisted")
  46.                 {
  47.                     countBlacklist++;
  48.                 }
  49.  
  50.                 else if (friend == "Lost")
  51.                 {
  52.                     countLost++;
  53.                 }
  54.             }
  55.  
  56.             Console.WriteLine($"Blacklisted names: {countBlacklist}");
  57.             Console.WriteLine($"Lost names: {countLost}");
  58.             Console.WriteLine(String.Join(" ", friends));
  59.         }
  60.  
  61.         public static List<string> Blacklist(List<string> friends, string[] command)
  62.         {
  63.             string name = command[1];
  64.  
  65.             if (friends.Contains(name))
  66.             {
  67.                 int indexBlacklist = friends.IndexOf(name);
  68.                 friends[indexBlacklist] = "Blacklisted";
  69.                
  70.                 Console.WriteLine($"{name} was blacklisted.");
  71.             }
  72.  
  73.             else
  74.             {
  75.                 Console.WriteLine($"{name} was not found");
  76.             }
  77.  
  78.             return friends;
  79.         }
  80.         public static List<string> Error(List<string> friends, string[] command)
  81.  
  82.         {
  83.             int indexError = int.Parse(command[1]);
  84.  
  85.             if (indexError>=0&& indexError<friends.Count)
  86.             {
  87.                 string nameError = friends.ElementAt(indexError);
  88.                 if (nameError != "Blacklisted" && nameError != "Lost")
  89.                 {
  90.  
  91.                     Console.WriteLine($"{nameError} was lost due to an error.");
  92.                     friends[indexError] = "Lost";
  93.                 }
  94.             }
  95.             return friends;
  96.         }
  97.  
  98.         public static List<string> Change(List<string> friends, string[] command)
  99.         {
  100.             int indexChange = int.Parse(command[1]);
  101.             string newnameChange = command[2];
  102.  
  103.             if (indexChange >= 0 && indexChange < friends.Count)
  104.             {
  105.                 string currentName = friends.ElementAt(indexChange);
  106.                 Console.WriteLine($"{currentName} changed his username to {newnameChange}.");
  107.                 friends[indexChange] = newnameChange;
  108.             }
  109.             return friends;
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement