记录连续车位的长度,小于等于3则+1,大于3则进行计算
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
using namespace std;
int main() {
string s;
getline(cin,s);
istringstream iss(s);
int num;
vector<int> park;
while(iss >> num){
park.push_back(num);
}//读入车位信息
int count = 0;
for(int i = 0;i<park.size();i++){
if(park[i]==0){
park[i] = 1;//先置为1
int b = i;//记录开始位置
int e = i+1;
while(park[e]==0&&e<park.size()){
park[e] = 1;
e++;
}
int len = e - b;
if(len<=3){
count++;
}
else{//连续车位>3
count = len/3;
if(len%3 != 0){
count++;
}
}
}
}
cout << count << endl;
}