Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02._Friendlist_Maintenance
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> list = Console.ReadLine().Split(", ").ToList();
- List<string> list1 = new List<string>();
- List<string> command = new List<string>();
- command.Add("");
- int numBL = 0;
- int numLost = 0;
- bool flag = true;
- while (command[0] != "Report")
- {
- command = Console.ReadLine()
- .Split()
- .ToList();
- if(command[0] == "Report")
- {
- break;
- }
- switch (command[0])
- {
- case "Blacklist":
- list1 = list;
- list = Blacklist(list, command[1]);
- flag = list1.SequenceEqual(list); // Има ли промяна в листа
- if (!flag)
- {
- numBL++; // ако има промяна, увеличавам брояча
- }
- break;
- case "Error":
- list1 = list;
- list = Error(list, command[1]);
- flag = list1.SequenceEqual(list); // Има ли промяна в листа
- if (!flag)
- {
- numLost++; // ако има промяна, увеличавам брояча
- }
- break;
- case "Change":
- list = Change(list, command[1], command[2]);
- break;
- }
- }
- Console.WriteLine($"Blacklisted names: {numBL}");
- Console.WriteLine($"Lost names: {numLost}");
- Console.WriteLine(string.Join(" ",list));
- }
- private static List<string> Change(List<string> arr, string v1, string name)
- {
- int index = int.Parse(v1);
- if (index >= 0 && index < arr.Count)
- {
- Console.WriteLine($"{arr[index]} changed his username to {name}.");
- arr[index] = name;
- }
- return arr;
- }
- private static List<string> Error(List<string> arr, string v)
- {
- int index = int.Parse(v);
- List<string> arrNew = new List<string>();
- for (int i = 0; i < arr.Count; i++)
- {
- arrNew.Add(arr[i]);
- }
- if (index >= 0 && index < arr.Count)
- {
- if (arr[index] != "Blacklisted" && arr[index] != "Lost")
- {
- Console.WriteLine($"{arr[index]} was lost due to an error.");
- arrNew[index] = "Lost";
- }
- }
- return arrNew;
- }
- private static List<string> Blacklist(List<string> arr, string name)
- {
- List<string> arrNew = new List<string>();
- for (int i = 0; i < arr.Count; i++)
- {
- arrNew.Add(arr[i]);
- }
- if (arr.Contains(name))
- {
- int index = arr.IndexOf(name);
- Console.WriteLine($"{name} was blacklisted.");
- arrNew[index] = "Blacklisted";
- }
- else
- {
- Console.WriteLine($"{name} was not found.");
- }
- return arrNew;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement