A - First Player Editorial by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
Your code will be accepted if it does exactly what is instructed in the problem statement. Specifically,
- first inspect the ages of all the \(N\) people to find the person number \(p\) of the youngest person;
- then, from person \(p\) in clockwise order, print the names of all the \(N\) people.
In order to inspect the ages of all the \(N\) people and print their names, you can use the standard loop feature (like the for statement) in a programming language.
In implementation, instead of numbering the \(N\) people as \(1, 2, \ldots, N\), we can decrease their numbers by one to number them as \(0, 1, \ldots, N-1\), so that the \(i\)-th person clockwise from person \(p\) (where the \(0\)-th person is considered person \(p\) him/herself) is conveniently found as person \((p + i) \bmod N\) (where \(x \bmod y\) denotes the remainder when \(x\) is divided by \(y\)).
The following is a sample code in C++ language.
#include <iostream>
#include <utility>
using namespace std;
int main(void)
{
int n, a[100];
string s[100];
cin >> n;
for(int i = 0; i < n; i++) cin >> s[i] >> a[i];
pair<int, int> m = {a[0], 0};
for(int i = 1; i < n; i++) m = min(m, {a[i], i});
int p = m.second;
for(int i = 0; i < n; i++) cout << s[(p+i)%n] << endl;
return 0;
}
posted:
last update: