链接和思路
OJ链接:传送门
本题思路很简单,只需要把国际象棋的局面单独标识即可。我使用C++容器map,注意需要重载运算符<
。
AC代码
#include <iostream>
#include <map>
using namespace std;
struct State {
string line[8];
bool operator<(const State &state) const {
for (int i = 0; i < 8; i++) {
if (this->line[i] != state.line[i])
return this->line[i] < state.line[i];
}
return false;
}
};
int main() {
int n;
cin >> n;
State *state = new State[n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < 8; ++j)
cin >> state[i].line[j];
map<State, int> cnt;
for (int i = 0; i < n; ++i) {
cnt[state[i]]++;
cout << cnt[state[i]] << endl;
}
delete[]state;
return 0;
}