public void Run() { var tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var token in tokens) { addCollection.Add(token); addRemoveCollection.Add(token); myList.Add(token); } Console.WriteLine(addCollection); Console.WriteLine(addRemoveCollection); Console.WriteLine(myList); int n = int.Parse(Console.ReadLine()); var addremove = new List <string>(); var mylist = new List <string>(); for (int i = 0; i < n; i++) { addremove.Add(addRemoveCollection.Remove()); mylist.Add(myList.Remove()); } Console.WriteLine(string.Join(" ", addremove)); Console.WriteLine(string.Join(" ", mylist)); }
public static void Main() { IAddCollection <string> addCollection = new AddCollection <string>(); IAddRemoveCollection <string> addRemoveCollection = new AddRemoveCollection <string>(); IMyList <string> myList = new MyList <string>(); var addCollectionIndexes = new StringBuilder(); var addRemoveCOllectionIndexes = new StringBuilder(); var myListIndexes = new StringBuilder(); var itemsToAdd = Console.ReadLine().Split(); var removeOperationsCount = int.Parse(Console.ReadLine()); foreach (var item in itemsToAdd) { addCollectionIndexes.Append($"{addCollection.Add(item)} "); addRemoveCOllectionIndexes.Append($"{addRemoveCollection.Add(item)} "); myListIndexes.Append($"{myList.Add(item)} "); } var addRemoveCollectionRemoveElements = new StringBuilder(); var myListRemoveElements = new StringBuilder(); for (int i = 0; i < removeOperationsCount; i++) { addRemoveCollectionRemoveElements.Append($"{addRemoveCollection.Remove()} "); myListRemoveElements.Append($"{myList.Remove()} "); } Console.WriteLine(addCollectionIndexes.ToString().Trim()); Console.WriteLine(addRemoveCOllectionIndexes.ToString().Trim()); Console.WriteLine(myListIndexes.ToString().Trim()); Console.WriteLine(addRemoveCollectionRemoveElements.ToString().Trim()); Console.WriteLine(myListRemoveElements.ToString().Trim()); }
static void Main() { var elements = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var numberOfRemoves = int.Parse(Console.ReadLine()); var addColectionsAdds = new StringBuilder(); var addRemoveColectionsAdds = new StringBuilder(); var myListAdds = new StringBuilder(); var addRemoveColectionsRemoves = new StringBuilder(); var myListRemoves = new StringBuilder(); var addColection = new AddCollection(); var addRemoveColectio = new AddRemoveCollection(); var myListColection = new MyList(); foreach (var element in elements) { addColectionsAdds.Append(addColection.Add(element) + " "); addRemoveColectionsAdds.Append(addRemoveColectio.Add(element) + " "); myListAdds.Append(myListColection.Add(element) + " "); } for (int i = 0; i < numberOfRemoves; i++) { addRemoveColectionsRemoves.Append(addRemoveColectio.Remove() + " "); myListRemoves.Append(myListColection.Remove() + " "); } Console.WriteLine(addColectionsAdds); Console.WriteLine(addRemoveColectionsAdds); Console.WriteLine(myListAdds); Console.WriteLine(addRemoveColectionsRemoves); Console.WriteLine(myListRemoves); }
public static void Main() { var inputElements = Console.ReadLine().Split(' '); var removeTimes = int.Parse(Console.ReadLine()); var addCollection = new AddCollection <string>(); var addRemoveCollection = new AddRemoveCollection <string>(); var myList = new MyList <string>(); var addCollectionAdded = new StringBuilder(); var addRemoveCollectionAdded = new StringBuilder(); var myListAdded = new StringBuilder(); var addRemoveCollectionRemoved = new StringBuilder(); var myListRemoved = new StringBuilder(); foreach (var inputElement in inputElements) { addCollectionAdded.Append($"{addCollection.Add(inputElement)} "); addRemoveCollectionAdded.Append($"{addRemoveCollection.Add(inputElement)} "); myListAdded.Append($"{myList.Add(inputElement)} "); } for (int i = 0; i < removeTimes; i++) { addRemoveCollectionRemoved.Append($"{addRemoveCollection.Remove()} "); myListRemoved.Append($"{myList.Remove()} "); } Console.WriteLine(addCollectionAdded); Console.WriteLine(addRemoveCollectionAdded); Console.WriteLine(myListAdded); Console.WriteLine(addRemoveCollectionRemoved); Console.WriteLine(myListRemoved); }
public static void Main() { IAddCollection <string> addCollection = new AddCollection <string>(); IAddRemoveCollection <string> addRemoveCollection = new AddRemoveCollection <string>(); IMyList <string> myList = new MyList <string>(); var elements = Console.ReadLine().Split(); var addCollectionAddIndexes = String.Empty; var addRemoveCollectionAddIndexes = String.Empty; var myListAddIndexes = String.Empty; int index; foreach (var element in elements) { index = addCollection.Add(element); addCollectionAddIndexes += index + " "; index = addRemoveCollection.Add(element); addRemoveCollectionAddIndexes += index + " "; index = myList.Add(element); myListAddIndexes += index + " "; } Console.WriteLine(addCollectionAddIndexes.Trim()); Console.WriteLine(addRemoveCollectionAddIndexes.Trim()); Console.WriteLine(myListAddIndexes.Trim()); var countOfRemoveOperations = int.Parse(Console.ReadLine()); var addRemoveCollectionRemoveElements = String.Empty; var myListAddRemoveElements = String.Empty; var elementToRemove = string.Empty; for (int i = 0; i < countOfRemoveOperations; i++) { elementToRemove = addRemoveCollection.Remove(); addRemoveCollectionRemoveElements += elementToRemove + " "; elementToRemove = myList.Remove(); myListAddRemoveElements += elementToRemove + " "; } Console.WriteLine(addRemoveCollectionRemoveElements.Trim()); Console.WriteLine(myListAddRemoveElements.Trim()); }