atcoder ABC 360-A题详解

atcoder ABC 360-A题详解

Problem Statement

Takahashi eats three plates for breakfast: rice, miso soup, and salad.

His table is long and narrow, so he arranged the three plates in a row. The arrangement is given by a string S, where the i-th plate from the left is rice if Si is R, miso soup if Si is M, and salad if Si is S.

Determine whether the plate of rice is to the left of the plate of miso soup.

Constraints

∣S∣=3
S contains one R, one M, and one S.

Input

The input is given from Standard Input in the following format:

S

Output

Print Yes if the plate of rice is to the left of the plate of miso soup, and No otherwise.

Sample Input 1

RSM

Sample Output 1

Yes
The plate of rice is at the 1st position from the left, and the plate of miso soup is at the 3rd position from the left. Since the plate of rice is to the left, print Yes.

Sample Input 2

SMR

Sample Output 2

No
The plates are arranged as salad, miso soup, and rice from left to right.

思路分析:

本题只要R在M的左边就可以了,可以分两种情况,第一,当R在最左边的话他是一定符合的,第二,当R在中间则需要判断是否符合,并且只差一个数字(即i与i➕1)。

code:

#include<iostream>
using namespace std;
char c[3];
int main(){
    for(int i=0;i<3;i++){
        cin>>c[i];
    }
    if(c[0]=='R'){
        cout<<"Yes";
        return 0;
    }
    for(int i=0;i<3;i++){
        if(c[i]=='R'&&c[i+1]=='M'){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}
  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值