Codeforces 538 A Cutting Banner

codeforces 538 A Cutting Banner
题目链接:
A. Cutting Banner
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.

There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.

Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.

Input

The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.

Output

Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).

Examples
input
CODEWAITFORITFORCES
output
YES
input
BOTTOMCODER
output
NO
input
DECODEFORCES
output
YES
input
DOGEFORCES
output
NO

题目大意:输入一个长度不超过100的字符串,问能不能删除一个子串得到"CODEFORCES"这个字符串(只能删一次)

思路:这道题想了很久也没想到一个好的解决方法,后来看了cf上的大神的代码,大多数大概就是用了c++函数库里的一个substr()函数(查找子串函数)很简明的一段代码完成的,还有一种就是直接暴力先一层循环找前i个子串,然后从i到length-1找后面的子串,看这两部分连接后能不能构成所求字符串。

代码1:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

#define m(a,b) memset(a,b,sizeof(a))
#define debug(x) cerr<<#x<<"="<<x<<endl;
typedef long long ll;

int main(){
	string s;
	while(cin>>s){
		int l=s.size();
		bool flag=false;
		for(int i=0;i<l;i++){
			for(int j=0;j<l;j++){
				if (s.substr(0,i)+s.substr(j+1)=="CODEFORCES")
					flag=true;
			}
		}
		if (flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
代码2:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

#define m(a,b) memset(a,b,sizeof(a))
#define debug(x) cerr<<#x<<"="<<x<<endl;
typedef long long ll;

int main(){
	string s;
	while(cin>>s){
		int l=s.size();
		bool flag=false;
		for(int i=0;i<l;i++){
			for(int j=i;j<l;j++){
				string s1;
				for(int k=0;k<i;k++)
					s1+=s[k];
				for(int k=j+1;k<l;k++)
					s1+=s[k];
				if (s1=="CODEFORCES"){
					flag=true;
					break;
				}
			}
		}
		if (flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}



猜你喜欢

转载自blog.csdn.net/codedz/article/details/79074542