Skip to content

Commit 8787d0e

Browse files
committed
finish 2024/25
1 parent bed50db commit 8787d0e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

2024/25/25.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <fstream>
2+
#include <iostream>
3+
#include <set>
4+
#include <string>
5+
#include <vector>
6+
7+
int main() {
8+
std::ifstream input_file("input.txt");
9+
if (!input_file) {
10+
std::cerr << "Error: Unable to open file." << std::endl;
11+
return -1;
12+
}
13+
14+
std::string input_line;
15+
std::vector<std::vector<std::string>> lks;
16+
std::vector<std::string> cur_lk;
17+
while (std::getline(input_file, input_line)) {
18+
if (input_line.size() == 0) {
19+
lks.push_back(cur_lk);
20+
cur_lk.clear();
21+
} else
22+
cur_lk.push_back(input_line);
23+
}
24+
lks.push_back(cur_lk);
25+
26+
int unique_lk_cnt = 0;
27+
for (int i = 0; i < lks.size(); ++i) {
28+
for (int j = i + 1; j < lks.size(); ++j) {
29+
auto lk_i = lks[i];
30+
auto lk_j = lks[j];
31+
bool is_key = false;
32+
bool is_lock = false;
33+
if (lk_i[0][0] == '#')
34+
is_lock = true;
35+
else
36+
is_key = true;
37+
if (lk_j[0][0] == '#')
38+
is_lock = true;
39+
else
40+
is_key = true;
41+
if (!is_key || !is_lock) continue;
42+
bool pos = true;
43+
for (int jj = 0; jj < lk_i[0].size(); ++jj) {
44+
for (int ii = 0; ii < lk_i.size(); ++ii) {
45+
if (lk_i[ii][jj] == '#' && lk_j[ii][jj] == '#') pos = false;
46+
}
47+
}
48+
if (pos) ++unique_lk_cnt;
49+
}
50+
}
51+
std::cout << unique_lk_cnt << std::endl;
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)