Codeforces 538 A. Cutting Banner-substr()函数字符串拼接
2 seconds
256 megabytes
standard input
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.
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.
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
CODEWAITFORITFORCES
YES
BOTTOMCODER
NO
DECODEFORCES
YES
DOGEFORCES
NO
题意就是条幅打错字母了,让你随便剪一次,剪去多余的字母,问你剩下的能否接成CODEFORCES的字样,要注意的是接的时候不可以改变顺序,只能剪一次!!!wa在没看清题意是剪一次。。。
一个很6的函数,直接就可以了。。。
substr函数用法举例:
substr('ABCDEFG', 0); //返回:ABCDEFG,截取所有字符
substr('ABCDEFG', 2); //返回:CDEFG,截取从C开始之后所有字符
substr('ABCDEFG', 0, 3); //返回:ABC,截取从A开始3个字符
substr('ABCDEFG', 0, 100); //返回:ABCDEFG,100虽然超出预处理的字符串最长度,但不会影响返回结果,系统按预处理字符串最大数量返回。
substr('ABCDEFG', -3); //返回:EFG,注意参数-3,为负值时表示从尾部开始算起,字符串排列位置不变
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
string str,str1;
int i,j;
cin>>str;
for(i=;i<str.size();i++){
for(j=i+;j<=str.size();j++){
str1=str.substr(,i)+str.substr(j);
if(str1=="CODEFORCES"){
printf("YES\n");
return ;
}
}
}
printf("NO\n");
return ;
}
Codeforces 538 A. Cutting Banner-substr()函数字符串拼接的更多相关文章
- Oracle函数--字符串拼接
常用的字符串聚合(拼接)函数介绍 1.WMSYS.WM_CONCAT 从oracle 10G开始支持,使用案例如下: select deptno,wmsys.wm_concat(ename) from ...
- Codeforces Round #300 A. Cutting Banner 水题
A. Cutting Banner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...
- 贪心 Codeforces Round #300 A Cutting Banner
题目传送门 /* 贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx, 接下来mx次循环,若是0,输出0:若是1,输出1,s[j]--: 注意:之前的0的要忽略 */ #inc ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
- 数据库截取字符串SUBSTR函数的使用
背景 今天中午做需求的时候,有类似于根据银行卡卡号的前几位判断出是哪个银行的情况,每个银行需要截取的位数都不一样,这时我就想到了SUBSTR 数据库截取字符串SUBSTR函数的使用 假设有一个表的结构 ...
- Hive substr 函数截取字符串
开发中,经常进行模糊查询或者进行截取字符串进行模糊匹配,常用的就是substr函数或者substring函数. 使用语法: substr(string A, int start),substring( ...
- PHP substr() 函数截取中文字符串乱码
用PHP substr() 函数截取中文字符串乱码,换PHPmb_substr() 函数即可
- PHP截取字符串函数substr()函数实例用法详解
在PHP中有一项非常重要的技术,就是截取指定字符串中指定长度的字符.PHP对于字符串截取可以使用PHP预定义函数substr()函数来实现.下面就来介绍一下substr()函数的语法及其应用. sub ...
- SQL中CHARINDEX()/INSTR()函数和SUBSTRING()/SUBSTR()函数
一.SQLServer中的CHARINDEX() 和ORACLE中的INSTR()函数 1.INSTR(C1,C2[,I[,J]]) [功能]在一个字符串中搜索指定的字符,返回发现指定的字符的位置; ...
随机推荐
- Generator实质
Generator实质 来源: <http://blog.liuwanlin.info/generatorshi-zhi/> superlin • September 15, 2015 ...
- [Leetcode] n queens ii n皇后问题
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- BZOJ1934 [Shoi2007]Vote 善意的投票 【最小割】
题目 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可以投和自己本来意愿 ...
- 洛谷 P2894 [USACO08FEB]酒店Hotel 解题报告
P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...
- 如何取消PPT中的动画效果
幻灯片放映——>设置放映式——>勾选放映时不加动画 (office2007)
- Docker Community Edition for CentOS
Docker CE for CentOS Docker CE for CentOS distribution is the best way to install the Docker platfor ...
- javascript实现倒计时(转)
<html> <head> <title>倒计时</title> <meta charset="utf-8"> < ...
- final 的作用
1.修饰类 类不能被继承 2.修饰方法 目的有二: 1)禁止子类重写该方法 2)执行效率(JVM相关的东西,不用太关注) 3.修饰变量 final修饰原始类型的变量,该变量不能被修改 final修饰引 ...
- 百练2505:A multiplication game
传送门:http://bailian.openjudge.cn/practice/2505/ [题解] 我们找找规律: 1~9显然是Stan wins. 10~18是Ollie wins. 19~16 ...
- noip2016 普及组
T1 买铅笔 题目传送门 #include<cstdio> #include<cstring> #include<algorithm> using namespac ...