Official
A - A Healthy Breakfast Editorial
by
A - A Healthy Breakfast Editorial
by
Cyanmond
初心者の方へ
- AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題 A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
- また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
例えば、以下のような手順でこの問題を解くことができます。
- 文字列変数
sを用意し、sに標準入力から入力を読み込む。 for文を用いるなどして、RMがそれぞれsのどこに含まれるかを調べる。 それぞれ index を変数pos_rpos_mに保存する。if文でpos_r < pos_mかどうかを判定し、そうであればYes、そうでなければNoを出力する。
他にも、 \(S\) としてあり得る文字列はたかだか \(6\) 通りしかないので、全て答えを手で求めておいて場合分けで解くこともできます。
C++ による実装例
#include <string>
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
int pos_r = -1, pos_m = -1;
for (int i = 0; i < 3; ++i) {
if (s[i] == 'R') {
pos_r = i;
}
if (s[i] == 'M') {
pos_m = i;
}
}
if (pos_r < pos_m) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
posted:
last update:
