Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Напишете програма която изисква от потребителя да въведе от клавиатурата две поредици от цели числа
- *съответно от N и K на брой елемента. Отпечатва всички числа, които присъстват в едната но не и в другата редица.
- Пример:
- Вход:
- N = 4
- { 8, 2, 10, 3 }
- K = 3
- { 6, 8, 3 }
- Изход: 2 10 6 */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04_NumbersOnlyInOneRange
- {
- class NumbersOnlyInOneRange
- {
- static void Main()
- {
- Console.Write("N = ");
- int n = Int32.Parse(Console.ReadLine());
- int[] array1 = new int [n];
- for (int i = 0; i < n; i++)
- {
- Console.Write("Element#{0} = ",i);
- array1[i] = Int32.Parse(Console.ReadLine());
- }
- Console.Write("K = ");
- int k = Int32.Parse(Console.ReadLine());
- int[] array2 = new int[k];
- for (int i = 0; i < k; i++)
- {
- Console.Write("Element#{0} = ", i);
- array2[i] = Int32.Parse(Console.ReadLine());
- }
- for (int i = 0; i < n; i++)
- {
- bool found = false;
- for (int j = 0; j < k; j++)
- {
- if (array1[i] == array2[j])
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- Console.Write(array1[i] + " ");
- }
- }
- for (int i = 0; i < k; i++)
- {
- bool found = false;
- for (int j = 0; j < n; j++)
- {
- if (array2[i] == array1[j])
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- Console.Write(array2[i] + " ");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment