Eagle Catching Chicks is a game that children enjoy playing. The gameplay involves one person acting as the eagle, another as the mother hen, and the rest as chicks. All the chicks must hide behind the mother hen. Once the game starts, the eagle will try to catch the chicks that can't keep up with the mother hen. When the eagle catches a chick, the round ends. The caught chick will then become the eagle, while the eagle will take the position of the caught chick and become a chick, and then the next round of the game begins. Please write a program to simulate the team situation after the game.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The input consists of five lines. The first line contains an integer N (2 ≤ N ≤ 2000), representing the total number of chicks. The second line contains N integers representing the initial player numbers acting as chicks, denoted as Ci (1 ≤ Ci ≤ 10000, 1 ≤ i ≤ N). The third line contains an integer E (1 ≤ E ≤ 10000), representing the initial player number acting as the eagle. The fourth line contains an integer Q (1 ≤ Q ≤ 200), representing the number of rounds in the game. The fifth line contains Q integers, representing the number of chicks caught in each round. Integers are separated by spaces. | Output a single line containing the sequence of chick numbers after Q rounds of the game. Numbers are separated by a single space. |
2 13 35 5 1 35 | 13 5 |
5 54 88 9 21 27 76 3 88 9 21 | 54 76 88 9 27 |
7 90 91 92 93 94 95 96 75 5 93 95 96 75 93 | 90 91 92 96 94 75 95 |
Thought Process
Use a Vector to collect the numbers of the chicks first. You can use Vector::iterator to determine the array position of a certain number. This way, you can swap the numbers between the eagle and the caught chick.
Sample Code-ZeroJudge F442: Eagle
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int>chicken;
for (int i = 0; i<N; i++)
{
int tmp;
cin >> tmp;
chicken.push_back(tmp);
}
int eagle;
cin >> eagle;
int Q;
cin >> Q;
for (int i = 0; i<Q; i++)
{
int tmp;
cin >> tmp;
vector<int>::iterator it = find(chicken.begin(), chicken.end(), tmp);
if (it != chicken.end())
{
swap(eagle, chicken[distance(chicken.begin(), it)]);
}
}
for (int i = 0; i<N; i++)
{
cout << chicken[i] << " ";
}
cout << "\n";
}
//ZeroJudge F442
//Dr. SeanXD