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.
- Prepare a string variable
s
. Read the input from Standard Input intos
. - Using a
for
statement, determine the position ofR
andM
ins
. Letpos_r
andpos_m
be those indices. - Use an
if
statement to determine ifpos_r < pos_m
. PrintYes
if it holds, andNo
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: