Please sign in first.
Official
B - フルコンボ/Full Combo Editorial
by
解説
B - フルコンボ/Full Combo Editorial
by
yuto1115
解説
繰り返しと条件分岐を用いて、与えられた文字列の組が問題文中の条件を満たすか判定すればよいです。All Perfect かどうか、Full Combo かどうか、Failed かどうかを別々に判定してもよいですが、以下のような処理を行うとまとめて判定することができます。
- 真偽値型の変数 \(\mathrm{AllPerfect,FullCombo}\) を用意し、どちらも true で初期化する。
- \(i=1,2,\dots,N\) それぞれについて以下を行う:
- \(S_i\) が
Perfectでないならば、\(\mathrm{AllPerfect}\) を false にする。その上、\(S_i\) がGreatでもないならば、\(\mathrm{FullCombo}\) を false にする。
- \(S_i\) が
- \(\mathrm{AllPerfect}\) が true ならば
All Perfectを、そうでなく \(\mathrm{FullCombo}\) が true ならばFull Comboを、どちらも false ならばFailedを出力する。
実装の詳細は下記の実装例 (C++, Python) を参考にしてください。
実装例 (C++) :
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
bool all_perfect = true;
bool full_combo = true;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s != "Perfect") {
all_perfect = false;
if (s != "Great") {
full_combo = false;
}
}
}
if (all_perfect) cout << "All Perfect" << endl;
else if (full_combo) cout << "Full Combo" << endl;
else cout << "Failed" << endl;
}
実装例 (Python) :
n = int(input())
all_perfect = True
full_combo = True
for i in range(n):
s = input()
if s != "Perfect":
all_perfect = False
if s != "Great":
full_combo = False
if all_perfect:
print("All Perfect")
elif full_combo:
print("Full Combo")
else:
print("Failed")
posted:
last update: