A - Overall Winner 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).
First, use a for statement to count Takahashi’s and Aoki’s wins. (You can count only one of them, and subtract it from to \(N\) to find the other.) If these numbers differ, the answer is determined, so print it. If they are the same, you need to find which player reached that number first. You can use a for statement in the implementation, or alternatively checking which player won the \(N\)-th game.
For specific implementations, see the sample codes below (C++ and Python). Note that in many languages, an array has \(0\)-based indexing.
C++
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int t = 0, a = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'T') ++t;
else ++a;
}
if (t > a) cout << 'T' << endl;
else if (t < a) cout << 'A' << endl;
else cout << char('T' + 'A' - s.back()) << endl;
}
Notes:
char('T' + 'A' - s.back())
in the last line evaluates to ‘A’
if s.back()
is ’T’
, and to ‘A’
if it is ’T’
.
Python
n = int(input())
s = input()
t = 0
a = 0
for i in range(0, n):
if s[i] == 'T':
t += 1
else:
a += 1
if t > a:
print('T')
elif t < a:
print('A')
elif s[-1] == 'A':
print('T')
else:
print('A')
posted:
last update: