Official

A - A Healthy Breakfast Editorial by en_translator


For beginners - If you are new to learning programming and do not know where to start, please try Problem A "[Welcome to AtCoder](https://atcoder.jp/contests/practice/tasks/practice_1)" from [practice contest](https://atcoder.jp/contests/practice/). 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). - 「C++入門 AtCoder Programming Guide for beginners (APG4b)」(https://atcoder.jp/contests/APG4b) is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.

For example, one can solve the problem as follows.

  1. Prepare a string variable s. Read the input from Standard Input into s.
  2. Using a for statement, determine the position of R and M in s. Let pos_r and pos_m be those indices.
  3. Use an if statement to determine if pos_r < pos_m. Print Yes if it holds, and No otherwise.

Alternatively, since there are only six possible strings for \(S\), one can find the answer by themself and use a conditional branch to print the answer.

Sample code in 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: