Venciity

[Jumpstart C#] ArraysAndLists TASK32

Feb 25th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. /*Задача М1-32.
  2.  * Дадени са три сортирани в нарастващ ред масиви A(M),B(N) и C(P).
  3.  * Да се определи един набор от индекси, за които Ai=Bj=Ck.
  4.  * Пред­полага се, че такива индекси съществуват.
  5.  
  6.  NOTE :  програмата разботи за всички набори от индексти :)   */
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13.  
  14. namespace task32
  15. {
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             int[] a = { 3, 4, 5, 6, 7, 9 };
  21.             int[] b = { 1, 2, 3, 4, 5, 6, 8 };
  22.             int[] c = { 4, 6, 9, 10 };
  23.  
  24.             int ai = 0, bi = 0, ci = 0; // индекси за масивите a,b,c
  25.  
  26.             while (true)
  27.             {
  28.                 int max =  Math.Max(a[ai],Math.Max(b[bi],c[ci])); // намираме максималното число
  29.  
  30.                 while (ai < a.Length && a[ai] < max)
  31.                 {
  32.                     ai++;
  33.                 }
  34.                 if (ai >= a.Length)
  35.                 {
  36.                     break;
  37.                 }
  38.  
  39.                 while (bi < b.Length && b[bi] < max)
  40.                 {
  41.                     bi++;
  42.                 }
  43.                 if (bi >= b.Length)
  44.                 {
  45.                     break;
  46.                 }
  47.  
  48.                 while (ci < c.Length && c[ci] < max)
  49.                 {
  50.                     ci++;
  51.                 }
  52.                 if (ci >= c.Length)
  53.                 {
  54.                     break;
  55.                 }
  56.  
  57.                 if (a[ai] == b[bi] && b[bi] == c[ci])
  58.                 {
  59.                     Console.WriteLine("{0} {1} {2}",ai,bi,ci);
  60.                     ai++; bi++; ci++;
  61.  
  62.                     if (ai >= a.Length || bi >= b.Length || ci >= c.Length )
  63.                     {
  64.                         break;
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment