A. Between the Offices

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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).

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,是就输出YES,不是就输出NO

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <string.h>
#include <string>
#include <cctype>
typedef long long ll;
#define INF 0x3f3f3f3f
#define mem memset
#define sc scanf
#define pr printf
using namespace std;
//inline int read(){
//	int X = 0, w = 0; char ch = 0;
//	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
//	while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
//	return w ? -X : X;
//}
//inline double dbread(){
//	double X = 0, Y = 1.0; int w = 0; char ch = 0;
//	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
//	while (isdigit(ch)) X = X * 10 + (ch ^ 48), ch = getchar();
//	ch = getchar();//读入小数点
//	while (isdigit(ch)) X += (Y /= 10) * (ch ^ 48), ch = getchar();
//	return w ? -X : X;
//}
//inline void write(int x){
//	if (x < 0) putchar('-'), x = -x;
//	if (x > 9) write(x / 10);
//	putchar(x % 10 + '0');
//}
int main() {
	ios::sync_with_stdio(false);
	int n;
	char s[105];
	mem(s, 0, sizeof(s));
	cin >> n;
	cin >> s;
	if (s[0] == 'S' && s[n - 1] == 'F') cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值