mamamaria

ass3

Feb 10th, 2021 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <iostream>
  2. //4-батовое поле посчитать количество 1
  3. #include <ctime>
  4. using namespace std;
  5. //На вход программы случайная строка, состоящая из n бит.Написать программу, вычисляющую оценку вероятности того,
  6. //что в этой строке есть точно две одинаковых непересекающихся подстроки длины m;
  7.  
  8. const int n = 15; const int m = 4;
  9.  
  10. void genStr(int mas[], int l) {
  11.     for (int i = 0; i < l; i++)
  12.         mas[i] = rand() % 2;
  13. }
  14. void output(int str[], int l) {
  15.     for (int i = 0; i < l; i++) {
  16.         cout << str[i];
  17.     }
  18. }
  19. int main()
  20. {
  21.     srand(time(NULL));
  22.  
  23.     /*int str[] = { 0,1,1,1,0,1,0,1,0,0,1,1,0,0,1 };
  24.     int subStr[] = { 1,0,1,0 };*/
  25.  
  26.     //int str[] = { 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0};
  27.     //int subStr[] = { 1,0,1,0 };
  28.  
  29.    
  30.     bool check = true; int counter = 0, gcounter = 0; double GK = 0; int N = 1000000;
  31.    
  32.     //output(str, n); cout << endl; output(subStr, m);
  33.     int str[n]; int subStr[m];
  34.     for (int k = 0; k < N; k++) {
  35.        
  36.         for (int s = 0; s < n; s++)
  37.             str[s] = rand() % 2; //call rand; and eax, 1 результат будет в eax
  38.         for (int t = 0; t < m; t++)
  39.             subStr[t] = rand() % 2;
  40.         for (int i = 0; i < n - m; ) {
  41.             for (int j = 0; j < m; j++) {
  42.                 if (subStr[j] == str[j + i]) {
  43.  
  44.                     check = true;
  45.                     counter++;
  46.                 }
  47.                 else check = false;
  48.                 if (check == false || counter == m)
  49.                 {
  50.                     if (counter == m) {
  51.                         gcounter++;
  52.                         i += m;
  53.                     }
  54.  
  55.                     counter = 0;
  56.                     break;
  57.                 }
  58.  
  59.             }
  60.             i++;
  61.         }
  62.         if (gcounter == 2)
  63.             GK += 1;
  64.         gcounter = 0;
  65.         counter = 0;
  66.     }
  67.  
  68.     cout << GK/N;
  69.     cout << endl;
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76. КЛАССНАЯ РАБОТА
  77. #include <iostream>
  78. using namespace std;
  79. int chislo;
  80. int main()
  81. {
  82.     cin >> chislo; int counter = 0;
  83.     __asm {
  84.         mov ebx, chislo
  85.         mov cx,0
  86.         A:
  87.         BT ebx, cx
  88.         jnc B
  89.         inc counter
  90.         B: inc cx
  91.         cmp cx, 32
  92.         jne A
  93.     }
  94.     cout << counter;
  95. }
Add Comment
Please, Sign In to add comment