House Party
Здравейте, дава ми 87/100, ако може помощ.
1.House Party
Write a program that keeps track of guests, that are going to a house party. On the first line of input, you are going to receive the number of commands you are going to receive. On the next lines you are going to receive one of the following messages:
- "{name} is going!"
- "{name} is not going!"
If you receive the first message, you have to add the person if he/she is not in the list and if he/she is in the list print on the console: "{name} is already in the list!". If you receive the second message, you have to remove the person if he/she is in the list and if not print: "{name} is not in the list!". At the end print all the guests.
Examples
Input |
Output |
4 Allie is going! George is going! John is not going! George is not going! |
John is not in the list! Allie |
5 Tom is going! Annie is going! Tom is going! Garry is going! Jerry is going! |
Tom is already in the list! Tom Annie Garry Jerry |
using System;
using System.Collections.Generic;
namespace House_Party
{
class Program
{
static void Main(string[] args)
{
int guests = int.Parse(Console.ReadLine());
List<string> goingOnParty = new List<string>();
for (int i = 0; i < guests; i++)
{
string command = Console.ReadLine();
string[] token = command.Split();
int goingCounter = 0;
for (int j = 0; j < goingOnParty.Count; j++)
{
if (token[2]=="going!" && token[0] == goingOnParty[j])
{
Console.WriteLine($"{token[0]} is already in the list!");
goingCounter++;
break;
}
}
if (goingCounter==0 && token[2] == "going!")
{
goingOnParty.Add(token[0]);
}
else if (token[2] == "not")
{
int removeCounter = 0;
for (int j = 0; j < goingOnParty.Count; j++)
{
for (int k = 0; k < goingOnParty.Count; k++)
{
if (token[0] == goingOnParty[k])
{
goingOnParty.Remove(token[0]);
removeCounter++;
break;
}
}
if (removeCounter == 1)
{
break;
}
if (goingOnParty[j] != token[0])
{
Console.WriteLine($"{token[0]} is not in the list!");
break;
}
}
}
}
for (int i = 0; i < goingOnParty.Count; i++)
{
Console.WriteLine(string.Join(" ", goingOnParty[i]));
}
}
}
}
Благодаря ти, много!