Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that takes as input two lists of names and removes from the first list all names given in the second list. The input and output lists are given as words, separated by a space, each list at a separate line.
- namespace _09.RemoveNames
- {
- using System;
- using System.Linq;
- public class RemoveNames
- {
- public static void Main(string[] args)
- {
- checked
- {
- Console.WriteLine("Enter all names from the First List on single line, separated by a space!");
- string[] firstList = ReadNamesFromInputAndCreateStringArray();
- Console.WriteLine("Enter all names from the Second List on single line, separated by a space!");
- string[] secondList = ReadNamesFromInputAndCreateStringArray();
- for (int i = 0; i < firstList.Length; i++)
- {
- bool nameIsInBothLists = secondList.Contains(firstList[i]);
- if (!nameIsInBothLists)
- {
- Console.Write("{0} ", firstList[i]);
- }
- }
- Console.WriteLine();
- }
- }
- private static string[] ReadNamesFromInputAndCreateStringArray()
- {
- checked
- {
- string inputLine = Console.ReadLine();
- char[] separators = new char[] { ' ', ',', ';' };
- string[] names = inputLine.Split(separators, StringSplitOptions.RemoveEmptyEntries);
- return names;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement