题目链接:http://codeforces.com/problemset/problem/538/A点击打开链接
解题思路:
several consecutive letters.(可以使用substr()函数)
在使用该函数的时候,需要注意:其截取子串的方向为从左到右。
如果你还不了解substr函数的用法,可以看我写的这个用法博客。点击打开链接
最后运行程序的时候,还是runtime error,因此自己检查后发现循环次数只需控制在i <= 10即可。
实现代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int i,j,flag = 0;
string first;
string second = "CODEFORCES";
cin >> first;
int len = first.length();
if(len <= 10)
cout << "NO" << endl;
else
{
for(i = 0;i <= 10; i++)
{
if(first.substr(0,i) + first.substr(len - 10 + i,10 - i) == second)
{
cout << "YES" << endl;
flag = 1;
break;
}
}
if(flag == 0)
cout << "NO" << endl;
}
return 0;
}
Welcome to my blog, and I hope what I write will help you.