zoukankan      html  css  js  c++  java
  • C

    Problem description

    As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.

    You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.

    Input

    The first line of input contains single integer n (2 ≤ n ≤ 100) — the number of days.

    The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.

    Output

    Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.

    You can print each letter in any case (upper or lower).

    Examples

    Input

    4
    FSSF

    Output

    NO

    Input

    2
    SF

    Output

    YES

    Input

    10
    FFFFFFFFFF

    Output

    NO

    Input

    10
    SSFFSFFSFF

    Output

    YES

    Note

    In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".

    In the second example you just flew from Seattle to San Francisco, so the answer is "YES".

    In the third example you stayed the whole period in San Francisco, so the answer is "NO".

    In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.

    解题思路:题目的意思就是如果字符串中S->F字符变化次数大于F->S的变化次数,则为"YES",否则为"NO",简单处理字符串!

    AC代码:

     1 #include<bits/stdc++.h>
     2 typedef long long LL;
     3 using namespace std;
     4 int main(){
     5     int n,i=0,t1=0,t2=0;char s[105];//t1表示S->F的变化次数,t2表示F->S的变化次数
     6     cin>>n;getchar();//吃掉回车符对字符串的影响
     7     cin>>s;
     8     while(s[i]!=''){
     9         if(s[i]=='S'){
    10             while(s[i]=='S')i++;
    11             if(s[i]!='')t1++;//不到末尾才可以加1,因为字符串中只有两个字符,既不是结束符,也跳出了上一步的循环,说明接下来的字符必为'F',则t1加1
    12         }
    13         else{
    14             while(s[i]=='F')i++;
    15             if(s[i]!='')t2++;//理由同上
    16         }
    17     }
    18     if(t1>t2)cout<<"YES"<<endl;
    19     else cout<<"NO"<<endl;
    20     return 0;
    21 }
  • 相关阅读:
    史上最简单的Hibernate入门简单介绍
    极客Web前端开发资源大荟萃
    ios7 UIScrollView 尺寸问题
    用ahk脚本自己主动删除flashcookies
    CSS文字样式
    Windows 10 安装
    万圣节福利:红孩儿3D引擎开发课程《3ds max导出插件初步》
    算法实验 层序列表问题(二叉树)
    git配置别名
    git忽略特殊文件
  • 原文地址:https://www.cnblogs.com/acgoto/p/9112201.html
Copyright © 2011-2022 走看看