Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CommonElements
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] arrOne = Console.ReadLine().Split();
- string[] arrTwo = Console.ReadLine().Split();
- string output = "";
- for (int i = 0; i < arrTwo.Length; i++)
- {
- for (int j = 0; j < arrOne.Length; j++)
- {
- if (arrOne[j] == arrTwo[i])
- {
- output += arrTwo[i] + ' ';
- }
- }
- }
- Console.WriteLine(output);
- }
- }
- }
- Решение с LINQ:
- using System;
- using System.Linq;
- namespace CommonElements
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] arrOne = Console.ReadLine().Split();
- string[] arrTwo = Console.ReadLine().Split();
- arrTwo = arrTwo.Where(x => arrOne.Contains(x)).ToArray();
- Console.WriteLine(string.Join(" ", arrTwo));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement