Advertisement
silvana1303

friendlist maintenance

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