#substr函数# Codeforces Round #300 A. Cutting Banner

Codeforces Round #300 A


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 somesubstring 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 stringAT), 'PLATE' (if you cut outTEM), 'T' (if you cut outEMPLATE), 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 wordCODEFORCES.

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

Output

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



扫描二维码关注公众号,回复: 939613 查看本文章

题目大意:


从一个字符串中截取任意一段的子字符串后,剩下部分能否构成目标字符串

 


解题思路:


由于只截取掉一段字符串,所以所需截取的字符串一定位于目标字符串的前面、末尾、中间部分




解题关键:


substr函数的应用



substr函数的用法:


substr(0, n);  substr(1, n);           都表示从字符串的头开始截取长度为n的字符串

例如:

string str = “hello world”;
      s = str.substr(2, 5);            //表示从第三位开始截取长度为5的字符串
      cout << s << endl;            // s 的输出结果为 “llo w”;


substr(n);                        表示从头开始截去长度为n的字符串后剩下的字符串

例如:

string str = “hello world”;
      s = str.substr(4);             //表示从头开始截去长度为4的字符串
      cout << s << endl;            // s 的输出结果为 “o world”;


本题代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

string word = "CODEFORCES";
string str;

int main() {
	cin >> str;
    for(int i = 0; i <= str.size(); i++) {
    	for(int j = i; j <= str.size(); j++) {
    		string s = str.substr(0, i) + str.substr(j);
    		if(s == word) {
    			cout << "YES" << endl;
    			return 0;
			}
		}
	}
	cout << "NO" << endl;
    return 0;
}


猜你喜欢

转载自blog.csdn.net/jasmineaha/article/details/79121939