题目
从官方网站查找即可
代码以及思路
代码如下
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class chess
{
public:
int times; // 出现次数
vector<string> line_pack; // 对应一到八行
chess(vector<string> temp)
{
line_pack = temp;
times = 1;
}
chess()
{
times = 0;
line_pack = {};
}
bool cmp_prechess(vector<string> prechess)
{
for (int i = 0; i < 8; i++)
{
if (this->line_pack[i] != prechess[i])
{
return false;
}
}
return true;
}
void timesadd(){
this->times++;
}
};
int main()
{
int n;
cin >> n;
string t;
vector<string> line_temp;
vector<chess> chess_pack;
for (int i = 0; i < n; i++)
{
for (int i = 0; i < 8; i++)
{
cin >> t;
line_temp.push_back(t);
}
int l = chess_pack.size();
bool flag=false;
for (int i = 0; i < l; i++)
{
chess chess_temp = chess_pack[i];
if (chess_temp.cmp_prechess(line_temp))
{
chess_pack[i].timesadd();//修改一下
cout << chess_pack[i].times << endl;
flag=true;
break;
}
}
if(flag==false)
{
cout << 1 << endl;
chess chess_eg(line_temp);
chess_pack.push_back(chess_eg); // 在加入之前应该进行检查
}
line_temp.clear();
}
return 0;
}
** 思路-**
因为此题比较简单,因此我在代码中已标出注释,结合注释阅读即可