Advertisement
HyperSensualNarwhal

sravnenie

Jan 10th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7.  
  8. #define TAB '\t';
  9. #define E2 cout << "\n\n";
  10. #define E4 cout << "\n\n\n\n";
  11. #define E10 cout << "\n\n\n\n\n\n\n\n\n\n";
  12.  
  13. void main()
  14. {
  15.     setlocale(LC_ALL, "Ru");
  16.     srand(time(NULL));
  17.  
  18.     const int size = 20;
  19.  
  20.     int Arona[size];
  21.     int Borea[size];
  22.     int Memories[size];
  23.  
  24.     int nmbr, tms, pstn;
  25.         cout << "Arona:" << TAB;
  26.     for (int i = 0; i < size; ++i)
  27.         cout << (Arona[i] = rand() % 10) << TAB;
  28.  
  29.     E2
  30.    
  31.         cout << "Borea:" << TAB;
  32.     for (int i = 0; i < size; ++i)
  33.         cout << (Borea[i] = rand() % 10) << TAB;
  34.  
  35.    
  36.  
  37.     E4
  38.  
  39.     for (int i = 0; i < size; ++i)
  40.     {
  41.         tms = 1;
  42.  
  43.         for (int j = 0; j < size; ++j)
  44.             Memories[j] = -1;
  45.  
  46.         for (int j = i + 1, l = 0; j < size; ++j, ++l)
  47.         {
  48.             if (Arona[i] == Borea[j])
  49.             {
  50.                 nmbr = Arona[i];
  51.                 tms += 1;
  52.                 pstn = j;
  53.                 Memories[l] = pstn;
  54.             }
  55.  
  56.         }
  57.  
  58.         for (int j = i - 1; j >= 0; --j)                          
  59.         {
  60.             if (nmbr == Borea[j]) tms = 1;
  61.             if (nmbr == Arona[i]) tms = 1;
  62.         }
  63.  
  64.         if (tms > 1)
  65.         {
  66.             cout << endl << "Количество встреч числа " << nmbr << " массива Arona в массиве Borea равно " << tms - 1<< endl;
  67.             cout << "Данное число имеет индекс " << i << " в массиве Arona";
  68.             cout << " и имеет индексы ";
  69.             for (int k = 0; k < size; ++k)
  70.             {
  71.                 if (Memories[k] >= 0)
  72.                 cout << Memories[k] << " ";
  73.             }
  74.               cout << " в массиве Borea" << endl;
  75.         }
  76.     }
  77.  
  78.     E10
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement