JulianJulianov

02. Common Elements Array

Feb 5th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. 02. Common Elements
  2. Write a program, which prints common elements in two arrays. You have to compare the elements of the second array to the elements of the first.
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace _02CommonElements
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. string[] firstArray = Console.ReadLine().Split();
  17. string[] secondArray = Console.ReadLine().Split();
  18.  
  19. string result = "";
  20. foreach (var firstWord in secondArray)
  21. {
  22. foreach (var nextWord in firstArray)
  23. {
  24. if (firstWord == nextWord)
  25. {
  26. result += firstWord + " ";
  27. }
  28. }
  29. }
  30. Console.WriteLine(result);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment