Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Second_attempt
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> friends = Console.ReadLine().Split(", ").ToList();
- string input = null;
- while ((input = Console.ReadLine()) != "Report")
- {
- string[] command = input.Split().ToArray();
- string action = command[0];
- switch (action)
- {
- case "Blacklist":
- friends = Blacklist(friends, command).ToList();
- // Console.WriteLine(String.Join(" ",friends));
- break;
- case "Error":
- friends = Error(friends, command);
- // Console.WriteLine(String.Join(" ", friends));
- break;
- case "Change":
- friends = Change(friends, command);
- // Console.WriteLine(String.Join(" ", friends));
- break;
- }
- }
- int countBlacklist = 0;
- int countLost = 0;
- foreach (string friend in friends)
- {
- if (friend == "Blacklisted")
- {
- countBlacklist++;
- }
- else if (friend == "Lost")
- {
- countLost++;
- }
- }
- Console.WriteLine($"Blacklisted names: {countBlacklist}");
- Console.WriteLine($"Lost names: {countLost}");
- Console.WriteLine(String.Join(" ", friends));
- }
- public static List<string> Blacklist(List<string> friends, string[] command)
- {
- string name = command[1];
- if (friends.Contains(name))
- {
- int indexBlacklist = friends.IndexOf(name);
- friends[indexBlacklist] = "Blacklisted";
- Console.WriteLine($"{name} was blacklisted.");
- }
- else
- {
- Console.WriteLine($"{name} was not found");
- }
- return friends;
- }
- public static List<string> Error(List<string> friends, string[] command)
- {
- int indexError = int.Parse(command[1]);
- if (indexError>=0&& indexError<friends.Count)
- {
- string nameError = friends.ElementAt(indexError);
- if (nameError != "Blacklisted" && nameError != "Lost")
- {
- Console.WriteLine($"{nameError} was lost due to an error.");
- friends[indexError] = "Lost";
- }
- }
- return friends;
- }
- public static List<string> Change(List<string> friends, string[] command)
- {
- int indexChange = int.Parse(command[1]);
- string newnameChange = command[2];
- if (indexChange >= 0 && indexChange < friends.Count)
- {
- string currentName = friends.ElementAt(indexChange);
- Console.WriteLine($"{currentName} changed his username to {newnameChange}.");
- friends[indexChange] = newnameChange;
- }
- return friends;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement