C++ code
Posted: Tue Jan 10, 2017 5:04 pm
Hi,
can you convert to livecode these few lines of C++?
I have no idea what they really do, but they works for a task...
can you convert to livecode these few lines of C++?
I have no idea what they really do, but they works for a task...
Code: Select all
#include <iostream>
#include <vector>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
void solve() {
int n; cin >> n;
array<string,2> s; cin >> s[0] >> s[1];
s[0] = "X" + s[0] + "X";
s[1] = "X" + s[1] + "X";
int ans = 0;
repeat (y,2) {
for (int l = 1; l <= n; ++l) {
if (s[y][l] == 'X') continue;
int r = l+1;
while (s[y][r] != 'X') ++ r;
if (r-l == 1) continue;
repeat_from (x,l,r) {
if (s[(y+1)%2][x-1] == 'X' and s[(y+1)%2][x] == '.' and s[(y+1)%2][x+1] == 'X') {
s[(y+1)%2][x] = 'X';
break;
}
}
repeat_from (x,l,r) s[y][x] = 'X';
ans += 1;
l = r;
}
}
repeat_from (x,1,n+1) {
if (s[0][x] == '.' or s[1][x] == '.') {
ans += 1;
}
}
cout << ans << endl;
}
int main() {
int testcases; cin >> testcases;
repeat (testcase, testcases) {
cout << "Case #" << testcase+1 << ": ";
solve();
}
return 0;
}