-
Notifications
You must be signed in to change notification settings - Fork 0
/
d1.cpp
48 lines (42 loc) · 815 Bytes
/
d1.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
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <vector>
using namespace std;
int main(int argc, char *argv[]){
string filename = argv[1];
ifstream fin;
fin.open(filename.c_str());
if (!fin)
{
cout << "Error opening " << filename << endl;
exit(1);
}
string d;
vector<int> depth;
while (getline(fin, d))
{
depth.push_back(stoi(d));
}
int inc = 0;
switch (stoi(argv[2]))
{
case 0:
for(int i=1;i<depth.size();i++){
if (depth[i] > depth[i-1]){
inc ++;
}
}
break;
case 1:
for(int i=1;i<depth.size()-2;i++){
if(depth[i+2]>depth[i-1]) inc++;
}
break;
default:
break;
}
std::cout << inc << std::endl;
return 0;
}