A - Majority 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).
Let \(f\) be the number of those such that \(S_i = \) For
. If \(f \gt \frac{N}{2}\), then the answer is Yes
; otherwise the answer is No
Soi it is sufficient to find \(f\).
Initialize a variable count
with 0
. If you “receive a string and increment count
by one if the received string equals For
, then you will obtain the desired \(f\) in count
when the process terminates. “Repeating \(N\) times” can be implemented with a for statement.
For more details, please refer to the following sample diagram. Note that this samples compares \(f\), and \(\frac{N}{2}\) rounded down.
Sample code (C++)
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
int count = 0;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s == "For") {
count += 1;
}
}
if (count > n / 2) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}
Sample code (Python)
n = int(input())
count = 0
for _ in range(n):
if input() == "For":
count += 1
print("Yes" if count > n // 2 else "No")
posted:
last update: