路灯代码
#include <iostream> #include <string> #include <vector> using namespace std; /*n个方格,亮pos pos-1 pos+1,X是障碍物*/ /*2 * 3 * ..x * 5 * ....x * */ /* * 1 * 2 * */ int main() { int num = 0;
int n = 0, k = 0;
int count = 0;
cin >> num;
int tmp = num;
vector<int> res(num, 0);
string str;
if (num >= 1 && num <= 1000) { do { cin >> n;
if (n >= 1 && n <= 1000) { cin >> str;
if (str.length() == n) { num--;
int i = 0;
while (i < str.length()) { if (str[i] == '.') { count++;
if (count == 3) { res[k]++;
count = 0;
} } else if (str[i] == 'x') { if (count == 0) { i++;
continue;
} res[k]++;
count = 0;
} else { break;
} ++i;
} } else { return 0;
} } else { return 0;
} if (count > 0) { res[k]++;
count = 0;
} k++;
} while (num > 0);
for (int i = 0; i < tmp; i++) { cout << res[i] << endl;
} } else { return 0;
} return 0; }
