-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
86 lines (71 loc) · 1.03 KB
/
main.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 <bits/stdc++.h>
using namespace std;
int
jumpingOnClouds(vector<int> c)
{
int count = 0;
int size = c.size();
int curr = 0;
while (curr < size-1)
{
if (curr+2 < size)
{
if (c[curr+2] == 0)
{
curr+=2;
count+=1;
}
else if (c[curr+1] == 0)
{
curr+=1;
count+=1;
}
else
break;
}
else
{
if (c[curr+1] == 0)
{
curr+=1;
count+=1;
}
break;
}
}
return count;
}
int
main(int argc, char **argv)
{
if (argc==1)
return 0;
ifstream filein (argv[1]);
string line;
int size;
string path;
vector<int> c;
if (filein.is_open())
{
getline ( filein, line );
size = stoi(line);
getline ( filein, line );
path = line;
filein.close();
}
else
{
cout << "Unable to open file";
return 0;
}
for (int i = 0; i < size; i++)
{
int c_item = 0;
if (path[i] != '0')
c_item = 1;
c.push_back( c_item );
}
int result = jumpingOnClouds(c);
cout << result << "\n";
return 0;
}