Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //4-батовое поле посчитать количество 1
- #include <ctime>
- using namespace std;
- //На вход программы случайная строка, состоящая из n бит.Написать программу, вычисляющую оценку вероятности того,
- //что в этой строке есть точно две одинаковых непересекающихся подстроки длины m;
- const int n = 15; const int m = 4;
- void genStr(int mas[], int l) {
- for (int i = 0; i < l; i++)
- mas[i] = rand() % 2;
- }
- void output(int str[], int l) {
- for (int i = 0; i < l; i++) {
- cout << str[i];
- }
- }
- int main()
- {
- srand(time(NULL));
- /*int str[] = { 0,1,1,1,0,1,0,1,0,0,1,1,0,0,1 };
- int subStr[] = { 1,0,1,0 };*/
- //int str[] = { 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0};
- //int subStr[] = { 1,0,1,0 };
- bool check = true; int counter = 0, gcounter = 0; double GK = 0; int N = 1000000;
- //output(str, n); cout << endl; output(subStr, m);
- int str[n]; int subStr[m];
- for (int k = 0; k < N; k++) {
- for (int s = 0; s < n; s++)
- str[s] = rand() % 2; //call rand; and eax, 1 результат будет в eax
- for (int t = 0; t < m; t++)
- subStr[t] = rand() % 2;
- for (int i = 0; i < n - m; ) {
- for (int j = 0; j < m; j++) {
- if (subStr[j] == str[j + i]) {
- check = true;
- counter++;
- }
- else check = false;
- if (check == false || counter == m)
- {
- if (counter == m) {
- gcounter++;
- i += m;
- }
- counter = 0;
- break;
- }
- }
- i++;
- }
- if (gcounter == 2)
- GK += 1;
- gcounter = 0;
- counter = 0;
- }
- cout << GK/N;
- cout << endl;
- }
- КЛАССНАЯ РАБОТА
- #include <iostream>
- using namespace std;
- int chislo;
- int main()
- {
- cin >> chislo; int counter = 0;
- __asm {
- mov ebx, chislo
- mov cx,0
- A:
- BT ebx, cx
- jnc B
- inc counter
- B: inc cx
- cmp cx, 32
- jne A
- }
- cout << counter;
- }
Add Comment
Please, Sign In to add comment