Advertisement
dimonstrer

Untitled

Sep 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6. const int n = 3;
  7. const int k = 1.5 * 59;
  8.  
  9. void randomGen(int mas[]);
  10. int hashing(int a);
  11. void print(int mas[]);
  12.  
  13. int main()
  14. {
  15.     setlocale(0, "");
  16.     int hash[k];
  17.     int mas[n];
  18.     randomGen(mas);
  19.     print(mas);
  20.     for (int i = 0; i < n; i++)
  21.         cout << mas[i] << endl << hashing(mas[i]) << endl;
  22.     system("pause");
  23. }
  24.  
  25. int hashing(int a)
  26. {
  27.     return a*a / 10 % 10;
  28. }
  29.  
  30. void randomGen(int mas[])
  31. {
  32.     srand(time(0));
  33.     for (int i = 0; i < n; i++)
  34.     {
  35.         mas[i] = 10 + rand() % 90;
  36.         for (int j = 0; j < i; j++)
  37.             if (mas[i] == mas[j])
  38.                 i--;
  39.     }
  40. }
  41.  
  42. void print(int mas[])
  43. {
  44.     for (int i = 0; i < n; i++) {
  45.         if (i < 9) {
  46.             cout << setw(3) << "[0" << i + 1 << "]";
  47.             cout << setw(5) << mas[i];
  48.         }
  49.         else {
  50.             if (i % 10 == 0)
  51.                 cout << endl;
  52.             cout << setw(2) << "[" << i + 1 << "]";
  53.             cout << setw(5) << mas[i];
  54.         }
  55.     }
  56.     cout << endl;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement