1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <cstdio>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include "poszukiwania.h"
#include "message.h"
using namespace std;


int main() {

	long long s = SignalLength();

	long long m = SeqLength();

	long long currentResult;

	long long result = 0;


	for(long long i = MyNodeId(); i <= (m - s); i += NumberOfNodes()){
		bool exists = true;
		for(int j = 1; j < s; ++j){
			if(SignalAt(j) != SeqAt(j+i)){
				exists = false;
			}
		}
		if(exists == true){
			currentResult = currentResult + 1;
		}
	}

	if (MyNodeId() > 0) {
		PutLL(0, currentResult);
	    Send(0);
	  } else {
		result = currentResult;
	    for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) {
	      Receive(instancja);
	      long long resultFromInstance = GetLL(instancja);
	      result = result + resultFromInstance;
	    }
	    printf("%llu", result);
	  }

	return 0;
}