softy_02

Friendlist Maintenance

Feb 27th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace FriendlistMaintenence
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> usernames = Console.ReadLine().Split(", ").ToList();
  12.             int blacklisted = 0;
  13.             int lost = 0;
  14.  
  15.             while (true)
  16.             {
  17.                 string line = Console.ReadLine();
  18.                 if (line == "Report")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 string[] input = line.Split();
  24.  
  25.                 switch (input[0])
  26.                 {
  27.                     case "Blacklist":
  28.                         string name = input[1];
  29.                         if (usernames.Contains(name))
  30.                         {
  31.                             for (int i = 0; i < usernames.Count; i++)
  32.                             {
  33.                                 if (usernames[i] == name)
  34.                                 {
  35.                                     usernames[i] = "Blacklisted";
  36.                                 }
  37.                             }
  38.                             Console.WriteLine($"{name} was blacklisted.");
  39.                         }
  40.                         else
  41.                         {
  42.                             Console.WriteLine($"{name} was not found.");
  43.                         }
  44.                         break;
  45.                     case "Error":
  46.                         int index = int.Parse(input[1]);
  47.                         string currentName = usernames[index];
  48.                         if (currentName != "Blacklisted" && currentName != "Lost" && index >= 0 && index < usernames.Count)
  49.                         {
  50.                             for (int i = 0; i < usernames.Count; i++)
  51.                             {
  52.                                 if (usernames[i] == currentName)
  53.                                 {
  54.                                     usernames[i] = "Lost";
  55.                                 }
  56.                             }
  57.                             Console.WriteLine($"{currentName} was lost due to an error.");
  58.                         }
  59.                         break;
  60.                     case "Change":
  61.                         int givenIndex = int.Parse(input[1]);
  62.                         string newName = input[2];
  63.                         string current = usernames[givenIndex];
  64.  
  65.                         if (givenIndex >= 0 && givenIndex < usernames.Count)
  66.                         {
  67.                             usernames[givenIndex] = newName;
  68.                             Console.WriteLine($"{current} changed his username to {newName}.");
  69.                         }
  70.                         break;
  71.                 }
  72.             }
  73.             foreach (var item in usernames)
  74.             {
  75.                 if (item == "Blacklisted")
  76.                 {
  77.                     blacklisted++;
  78.                 }
  79.                 if (item == "Lost")
  80.                 {
  81.                     lost++;
  82.                 }
  83.             }
  84.             Console.WriteLine($"Blacklisted names: {blacklisted}");
  85.             Console.WriteLine($"Lost names: {lost}");
  86.             Console.WriteLine(string.Join(" ", usernames));
  87.         }
  88.     }
  89. }
Add Comment
Please, Sign In to add comment