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 ...
随机推荐
- CAD插入jpg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- ceph对接openstack环境
环境准备: 保证openstack节点的hosts文件里有ceph集群的各个主机名,也要保证ceph集群节点有openstack节点的各个主机名 一.使用rbd方式提供存储如下数据: (1)image ...
- Fiddler构造请求
Fiddler工具是一个http协议调试代理工具,它可以帮助程序员测试或调试程序,辅助web开发. Fiddler工具可以发送向服务端发送特定的HTTP请求以及接受服务器回应的请求和数据,是web调试 ...
- 【上海站】EOLINKER 用户培训之旅,等你来共建API新连接
从今年3月4日起,EOLINKER AMS 团队将再次开启全国用户培训之旅.本次全国培训之旅依旧将覆盖北上广深等国内主要城市,重点提供两种服务内容,一是 对 EOLINKER 产品的交流,包括 API ...
- Luogu P1256 显示图像
P1256 显示图像 题目描述 古老的显示屏是由N×M个像素(Pixel)点组成的.一个像素点的位置是根据所在行数和列数决定的.例如P(2,1)表示第2行第1列的像素点.那时候,屏幕只能显示黑与白两种 ...
- 初学者对ASCII编码、Unicode编码、UTF-8编码的理解
最早的计算机在设计时采用8个比特(bit)作为一个字节(byte),所以,一个字节能表示的最大的整数就是 255(二进制 11111111=十进制 255),如果要表示更大的整数,就必须用更多的字节. ...
- C C++ POSIX 的一些 IO 操作
一些 C C++ POSIX 的 IO 操作总结 文件-内存之间 内存-内存之间 POSIX 有无缓冲的 IO 操作 对文件的操作,读文件至内存,从内存写至文件 // 读文件至内存buf中 void ...
- Linux - redis持久化RDB与AOF
目录 Linux - redis持久化RDB与AOF RDB持久化 redis持久化之AOF redis不重启,切换RDB备份到AOF备份 确保redis版本在2.2以上 实验环境准备 备份这个rdb ...
- 【Codeforces 27A】Next Test
[链接] 我是链接,点我呀:) [题意] 让你求没出现过的最小值 [题解] 模拟..for一下就好 [代码] import java.io.*; import java.util.*; public ...
- Spark源码值提交任务
/** * Return the number of elements in the RDD. */ def count(): Long = sc.runJob(this, Utils.getIt ...