Venciity

[Jumpstart C#] Arrays 04-NumbersOnlyInOneRange

Feb 17th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. /*Напишете програма която изисква от потребителя да въведе от клавиатурата две поредици от цели числа
  2.  *съответно от N и K на брой елемента. Отпечатва всички числа, които присъстват в едната но не и в другата редица.
  3.   Пример:
  4.   Вход:
  5.   N = 4
  6.   { 8, 2, 10, 3 }
  7.   K = 3
  8.   { 6, 8, 3 }
  9.   Изход: 2 10 6   */
  10.  
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16.  
  17. namespace _04_NumbersOnlyInOneRange
  18. {
  19.     class NumbersOnlyInOneRange
  20.     {
  21.         static void Main()
  22.         {
  23.             Console.Write("N = ");
  24.             int n = Int32.Parse(Console.ReadLine());
  25.             int[] array1 = new int [n];
  26.             for (int i = 0; i < n; i++)
  27.             {
  28.                 Console.Write("Element#{0} = ",i);
  29.                 array1[i] = Int32.Parse(Console.ReadLine());
  30.             }
  31.  
  32.             Console.Write("K = ");
  33.             int k = Int32.Parse(Console.ReadLine());
  34.             int[] array2 = new int[k];
  35.             for (int i = 0; i < k; i++)
  36.             {
  37.                 Console.Write("Element#{0} = ", i);
  38.                 array2[i] = Int32.Parse(Console.ReadLine());
  39.             }
  40.  
  41.             for (int i = 0; i < n; i++)
  42.             {
  43.                 bool found = false;
  44.                 for (int j = 0; j < k; j++)
  45.                 {
  46.                     if (array1[i] == array2[j])
  47.                     {
  48.                         found = true;
  49.                         break;
  50.                     }
  51.                 }
  52.                 if (!found)
  53.                 {
  54.                     Console.Write(array1[i] + " ");
  55.                 }
  56.             }
  57.  
  58.             for (int i = 0; i < k; i++)
  59.             {
  60.                 bool found = false;
  61.                 for (int j = 0; j < n; j++)
  62.                 {
  63.                     if (array2[i] == array1[j])
  64.                     {
  65.                         found = true;
  66.                         break;
  67.                     }
  68.                 }
  69.                 if (!found)
  70.                 {
  71.                     Console.Write(array2[i] + " ");
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment