advent-of-code/2023/14/main-1.cpp

32 lines
559 B
C++
Raw Normal View History

2023-12-16 16:52:32 -08:00
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vector<string> lines;
string line;
while (getline(cin, line) && !line.empty()) {
lines.push_back(line);
}
int ret = 0;
for (unsigned int r = 0; r < lines.size(); r++) {
for (unsigned int c = 0; c < lines[r].size(); c++) {
if (lines[r][c] == 'O') {
lines[r][c] = '.';
int rr = r;
while (rr != 0 && lines[rr - 1][c] == '.') {
rr--;
}
lines[rr][c] = 'O';
ret += lines.size() - rr;
}
}
}
cout << ret << '\n';
}