Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- namespace ConsoleApp1
- {
- class Exam
- {
- static void Main(string[] args)
- {
- List<string> names = Console.ReadLine().Split(", ").ToList();
- string[] command = Console.ReadLine().Split().ToArray();
- int lostCounter = 0;
- int blackCounter = 0;
- while (command[0] != "Report")
- {
- if (command[0] == "Blacklist")
- {
- blackCounter = Blacklist(names, command, blackCounter);
- }
- else if (command[0] == "Error")
- {
- lostCounter = Error(names, command, lostCounter);
- }
- else if (command[0] == "Change")
- {
- Change(names, command);
- }
- command = Console.ReadLine().Split().ToArray();
- }
- Console.WriteLine($"Blacklisted names: {blackCounter}");
- Console.WriteLine($"Lost names: {lostCounter}");
- Console.WriteLine(string.Join(" ", names));
- }
- private static void Change(List<string> names, string[] command)
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < names.Count)
- {
- string nameOld = names[index];
- string newName = command[2];
- names[index] = newName;
- Console.WriteLine($"{nameOld} changed his username to {newName}.");
- }
- }
- private static int Error(List<string> names, string[] command, int lostCounter)
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < names.Count)
- {
- if (names[index] != "Blacklisted" && names[index] != "Lost")
- {
- string name = names[index];
- names[index] = "Lost";
- Console.WriteLine($"{name} was lost due to an error.");
- lostCounter++;
- }
- }
- return lostCounter;
- }
- private static int Blacklist(List<string> names, string[] command, int blackCounter)
- {
- string name = command[1];
- if (names.Contains(command[1]))
- {
- names[names.IndexOf(name)] = "Blacklisted";
- Console.WriteLine($"{name} was blacklisted.");
- blackCounter++;
- }
- else
- {
- Console.WriteLine($"{name} was not found.");
- }
- return blackCounter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement