static void Main()
{
StringBuilder output = new StringBuilder();
string commandLine = Console.ReadLine();
SupermarketQueue supermarketQueue = new SupermarketQueue();
while (commandLine != EndCommand)
{
string[] command = commandLine.Split(' ');
switch (command[0])
{
case AppendCommand:
supermarketQueue.Append(command[1]);
output.AppendLine(OKMessage);
break;
case InsertCommand:
if (supermarketQueue.Insert(int.Parse(command[1]), command[2]))
{
output.AppendLine(OKMessage);
}
else
{
output.AppendLine(ErrorMessage);
}
break;
case FindCommnad:
output.AppendFormat("{0}{1}", supermarketQueue.Find(command[1]), Environment.NewLine);
break;
case ServeCommand:
var served = supermarketQueue.Serve(int.Parse(command[1]));
if (served != null)
{
output.AppendLine(string.Join(" ", served));
}
else
{
output.AppendLine(ErrorMessage);
}
break;
}
commandLine = Console.ReadLine();
}
Console.Write(output);
}