Advertisement
gospod1978

MidExam/Group2/Friendlist Maintenance

Nov 12th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.  
  12.             List<string> friends = Console.ReadLine().Split(", ").ToList();
  13.             string input = string.Empty;
  14.            
  15.  
  16.             while ((input = Console.ReadLine()) != "Report")
  17.             {
  18.                 string[] array = input.Split();
  19.                 string command = array[0];
  20.                 if (command == "Blacklist")
  21.                 {
  22.                     string name = array[1];
  23.                     if (!friends.Contains(name))
  24.                     {
  25.                         Console.WriteLine($"{name} was not found.");
  26.                     }
  27.                     else
  28.                     {
  29.                         int bla = friends.IndexOf(name);
  30.                         friends.Insert(bla, "Blacklisted");
  31.                         friends.RemoveAt(bla + 1);
  32.                         Console.WriteLine($"{name} was blacklisted.");
  33.                     }
  34.                 }
  35.                 else if (command == "Error")
  36.                 {
  37.                     int index = int.Parse(array[1]);
  38.                     string current = friends[index];
  39.                     if(current != "Blacklisted" && current != "Lost")
  40.                     {
  41.                         friends.Insert(index, "Lost");
  42.                         friends.RemoveAt(index + 1);
  43.                         Console.WriteLine($"{current} was lost due to an error.");
  44.                     }
  45.  
  46.                 }
  47.                 else if (command == "Change")
  48.                 {
  49.                     int change = int.Parse(array[1]);
  50.                     string newName = array[2];
  51.                     if (change >= 0 && change < friends.Count)
  52.                     {
  53.                         friends.Insert(change, newName);
  54.                         string oldName = friends[change + 1];
  55.                         friends.RemoveAt(change + 1);
  56.                         Console.WriteLine($"{oldName} changed his username to {newName}.");
  57.                     }
  58.                 }
  59.             }
  60.             int black = 0;
  61.             int lost = 0;
  62.             for (int i = 0; i < friends.Count; i++)
  63.             {
  64.                 if (friends[i] == "Blacklisted")
  65.                 {
  66.                     black++;
  67.                 }
  68.                 if (friends[i] == "Lost")
  69.                 {
  70.                     lost++;
  71.                 }
  72.             }
  73.             Console.WriteLine($"Blacklisted names: {black}");
  74.             Console.WriteLine($"Lost names: {lost}");
  75.             Console.WriteLine(string.Join(" ", friends));
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement