把每条线加入集合,最后求集合大小即可
#include <bits/stdc++.h>
using namespace std;
char s[5][5];
set< set<char> > e[5];
void q(vector< pair<int, int> > c) {
set<char> se; se.clear();
for(auto it: c) se.insert(s[it.first][it.second]);
e[se.size()].insert(se);
}
int main() {
for (int i = 1; i <= 3; i++) cin >> (s[i] + 1);
for (int i = 1; i <= 3; i++) q({{i, 1}, {i, 2}, {i, 3}}); //行
for (int i = 1; i <= 3; i++) q({{1, i}, {2, i}, {3, i}}); //列
//对角线
q({{1, 1}, {2, 2}, {3, 3}});
q({{3, 1}, {2, 2}, {1, 3}});
printf("%d\n%d\n", e[1].size(), e[2].size());
return 0;
}
orz
写的很好的代码 !