View difference between Paste ID: NKT5bnKL and mU2VGPTU
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include <ctime>
3
using namespace std;
4
//На вход программы случайная строка, состоящая из n бит.Написать программу, вычисляющую оценку вероятности того, 
5
//что в этой строке есть точно две одинаковых непересекающихся подстроки длины m;
6
7
const int n=15; const int m = 4;
8
9
void genStr(int mas[], int l) {
10
	for (int i = 0; i < l; i++)
11
		mas[i] = rand() % 2;
12
}
13
void output(int str[], int l) {
14
	for (int i = 0; i < l; i++) {
15
		cout << str[i];
16
	}
17
}
18
int main()
19
{
20
	int str[n]; int subStr[m]; bool check = true; int counter = 0, gcounter = 0;
21
	genStr(str,n);
22
	genStr(subStr,m);
23
	output(str,n); cout << endl; output(subStr,m);
24
25
	for (int i = 0; i < n-m; i++) {
26
		for (int j = 0; j < m; j++) {
27
			if (subStr[j] == str[j + i]) {
28
				check = true;
29
			}
30
			else {
31
				if (check == true) gcounter++;
32
				check = false;
33
				break;
34
			}
35
		}
36
	}
37
	cout << endl;
38
	cout << gcounter;
39
	cout << endl;
40
41
}