Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

NikolayNeykov92 avatar NikolayNeykov92 617 Точки
Best Answer

Здравей,

грешката ти е при подреждането на проверките при нова регистрация.

Ето поправката:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            int numberOfCommands = int.Parse(Console.ReadLine());
            Dictionary<string, string> usernamePlate = new Dictionary<string, string>();
            for (int i = 0; i < numberOfCommands; i++)
            {
                string inputLine = Console.ReadLine();
                var elements = inputLine.Split(' ').ToArray();
                string command = elements[0];
                string username = elements[1];

                if (command == "register")
                {
                    string licensePlate = elements[2];
                    bool isValidPlate = licensePlate.Length == 8
                        && char.IsUpper(licensePlate[0])
                        && char.IsUpper(licensePlate[1])
                        && char.IsUpper(licensePlate[7])
                        && char.IsUpper(licensePlate[6])
                        && char.IsDigit(licensePlate[2])
                        && char.IsDigit(licensePlate[3])
                        && char.IsDigit(licensePlate[4])
                        && char.IsDigit(licensePlate[5]);

                    if (usernamePlate.ContainsKey(username))
                    {
                        Console.WriteLine($"ERROR: already registered with plate number {usernamePlate[username]}");
                    }
                    else if (!isValidPlate)
                    {
                        Console.WriteLine($"ERROR: invalid license plate {licensePlate}");
                    }
                    else if (usernamePlate.ContainsValue(licensePlate))
                    {
                        Console.WriteLine($"ERROR: license plate {licensePlate} is busy");
                    }
                    else if (!usernamePlate.ContainsKey(username))
                    {
                        usernamePlate.Add(username, licensePlate);
                        Console.WriteLine($"{username} registered {licensePlate} successfully");
                    }
                }
                else if(command=="unregister")
                {
                    if (!usernamePlate.ContainsKey(username))
                    {
                        Console.WriteLine($"ERROR: user {username} not found");
                    }
                    else
                    {
                        Console.WriteLine($"user {username} unregistered successfully");
                        usernamePlate.Remove(username);
                    }
                }
            }
            foreach (var item in usernamePlate)
            {
                Console.WriteLine($"{item.Key} => {item.Value}");
            }
        }
    }
}

Условието от задачата:

  • The system only supports one car per user at the moment, so if a user tries to register another license plate, using the same username, the system should print:
    “ERROR: already registered with plate number {licensePlateNumber}”
  • If the license plate is invalid, the system should print:
    “ERROR: invalid license plate {licensePlateNumber}“
  • If the user tries to register someone else’s license plate, the system should print:
    “ERROR: license plate {licensePlateNumber} is busy”
  • If the aforementioned checks pass successfully, the plate can be registered, so the system should print:
    “{username} registered {licensePlateNumber} successfully”
1
26/06/2018 11:41:26
georgivelev4 avatar georgivelev4 2 Точки

Благодаря !

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.