day23a.cpp (935B)
1 #include <algorithm> 2 #include <cstdint> 3 #include <iostream> 4 #include <map> 5 #include <queue> 6 #include <ranges> 7 #include <set> 8 #include <sstream> 9 #include <string> 10 #include <string_view> 11 #include <vector> 12 using namespace std; 13 14 set<int> computers; 15 bool m[26*26][26*26]; 16 17 int index(char a, char b) { return (int)(a-'a') + 26*(int)(b-'a'); } 18 bool t(int i) { return i % 26 == 't' - 'a'; } 19 20 int main() { 21 string line; 22 while (getline(cin, line)) { 23 int i = index(line[0], line[1]); 24 int j = index(line[3], line[4]); 25 computers.insert(i); 26 computers.insert(j); 27 m[i][j] = m[j][i] = true; 28 } 29 30 vector cv(computers.begin(), computers.end()); 31 int tot = 0; 32 for (unsigned i = 0; i < cv.size(); i++) 33 for (unsigned j = i+1; j < cv.size(); j++) 34 for (unsigned k = j+1; k < cv.size(); k++) 35 tot += m[cv[i]][cv[j]] && m[cv[j]][cv[k]] && m[cv[k]][cv[i]] && 36 (t(cv[i]) || t(cv[j]) || t(cv[k])); 37 38 cout << tot << endl; 39 return 0; 40 }