C - Between the Offices
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代码:
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
int main(){
int n,i=,t1=,t2=;char s[];//t1表示S->F的变化次数,t2表示F->S的变化次数
cin>>n;getchar();//吃掉回车符对字符串的影响
cin>>s;
while(s[i]!='\0'){
if(s[i]=='S'){
while(s[i]=='S')i++;
if(s[i]!='\0')t1++;//不到末尾才可以加1,因为字符串中只有两个字符,既不是结束符,也跳出了上一步的循环,说明接下来的字符必为'F',则t1加1
}
else{
while(s[i]=='F')i++;
if(s[i]!='\0')t2++;//理由同上
}
}
if(t1>t2)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}
C - Between the Offices的更多相关文章
- 如何去破解所有的window和offices(超级全面)
破解所有的Windows和Offices by方阳 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7107666.html 摘 ...
- offices 激活
http://www.xitongcheng.com/jiaocheng/dnrj_article_44577.html 破解工具见cnblos文件中 : https://blog.csdn.net ...
- LA4273 Post Offices
题目戳这里. 村庄排序.状态\(f[j][i]\)表示考虑前\(i\)个村庄,造\(j\)个邮局且\(i\)造了邮局的最小代价.我们用\(Lb_i,Rb_i\)表示在第\(i\)个村庄造邮局,邮局最左 ...
- 【Codeforces Round #437 (Div. 2) A】Between the Offices
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...
- 【12-26】go.js
var $ = go.GraphObject.make; // for conciseness in defining templates function buildAlarm(row,column ...
- HDOJ 4770 Lights Against Dudely
状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- POJ 1160 题解
Post Office Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18835 Accepted: 10158 Des ...
- Java基础之类Class使用
大家都知道Java是一门面向对象编程语言,在Java世界里,万事万物皆对象,那个Java中怎么表示对象呢?Class 我们知道Java中的对象都是Object类的子类,那么今天我们就一起来研究一下Ja ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q128-Q130)
Question 128 You are designing a SharePoint 2010 solution that includes a custom site definition an ...
随机推荐
- auto类型推导
引言 auto : 类型推导. 在使用c++的时候会经常使用, 就像在考虑STL时迭代器类型, 写模板的时候使用auto能少写代码, 也能帮助我们避免一些隐患的细节. auto初始化 使用auto型别 ...
- Cat VS Dog HDU_3829(最大独立集最大匹配)
Cat VS Dog 题意:一群小朋友去动物园,如果每个小朋友喜欢的动物是猫,那么不喜欢的动物一定是狗,反之也是.现在动物园的管理者要拿走一些动物,如果拿走的是某个小朋友不喜欢的动物,那这个小朋友就非 ...
- Linux之强大的selinux
简单点说,SELinux就是用来加强系统安全性的.它给一些特定程序(这些程序也在不断增加)做了一个沙箱,它将文件打上了一个安全标签,这些标签属于不同的类,也只能执行特定的操作,也就是规定了某个应用程序 ...
- 00.模块1.模块(Module)和包(Package)
转自廖雪峰老师官方网站 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件 ...
- Python2 下Ubuntu linux Mac 安装 PyV8
在pip install PyV8(注意区分大小写)时,出现了如下报错 command 'x86_64-linux-gnu-gcc' failed with exit status 1 解决方案: 百 ...
- Spring MVC 单元测试Demo
@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations={" ...
- bug的分类和等级
一.bug的定义 软件的bug,狭义指软件程序的漏洞或缺陷,广义指测试工程师或用户提出的软件可改进的细节.或与需求文档存在差异的功能实现等 对应三个测试目的:(3个为了) 1.为了发现程序的代码或业务 ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
- js es6 Object.freeze
将对象冻结,使用Object.freeze方法 const foo = Object.freeze({}); // 常规模式时,下面一行不起作用: // 严格模式时,该行会报错 foo.prop = ...
- 详解Pattern类和Matcher类
java正则表达式通过java.util.regex包下的Pattern类与Matcher类实现(建议在阅读本文时,打开java API文档,当介绍到哪个方法时,查看java API中的方法说明,效果 ...