-
Notifications
You must be signed in to change notification settings - Fork 1
/
Treceri prin zero semnal.cpp
86 lines (55 loc) · 1.42 KB
/
Treceri prin zero semnal.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include <numeric>
using namespace std;
int main(){
int n;
float x;
float medie=0,suma=0;
int cnt=0;
vector<float>vec;
cin>>n;
for(int i=0;i<n;i++){
cin>>x;
vec.push_back(x);
}
float w;
cin>>w;
vector<float>aux;
while(vec.size()>=w){
for(int i=0;i<w;i++){
aux.push_back(vec[i]);
}
for(int i=0;i<aux.size();i++){
//cout<<aux[i]<<' ';
suma=suma+aux[i];
}
medie=suma/w;
for(int i=0;i<aux.size()-1;i++){
if(aux[i]<medie&&aux[i+1]>medie||aux[i]>medie&&aux[i+1]<medie){
cnt++;
}
}
cout<<cnt<<endl;
medie=0;suma=0;cnt=0;
aux.clear();
for(int i=0;i<w;i++){
vec.erase(vec.begin());
}
}
cnt=0;suma=0;medie=0;
if(vec.size()>0){
for(int i=0;i<vec.size();i++){
suma+=vec[i];
}
medie=suma/vec.size();
for(int i=0;i<vec.size()-1;i++){
if(vec[i]<medie&&vec[i+1]>medie||vec[i]>medie&&vec[i+1]<medie){
cnt++;
}
}
cout<<cnt<<endl;
}
}