ACM--字符串--Two Substrings--水

题目地址:传送门

D - Two Substrings

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u

Submit Status

Description

You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB"
and "BA" (the substrings can go in any order).

Input

The only line of input contains a string s of length between 1 and 105 consisting
of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA",
and "NO" otherwise.

Sample Input

Input

ABA

Output

NO

Input

BACFAB

Output

YES

Input

AXBYBXA

Output

NO

Hint

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".

题解:这里可以使用strstr()函数,需要<string.h>头文件

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char s[100001];
int main(){
   char *c;
   scanf("%s",&s);
   if((c=strstr(s,"AB"))!=NULL&&strstr(c+2,"BA")!=NULL){
        printf("YES\n");
        return 0;
   }
   if((c=strstr(s,"BA"))!=NULL&&strstr(c+2,"AB")!=NULL){
        printf("YES\n");
        return 0;
   }
   printf("NO\n");
}
时间: 2024-08-30 05:49:10

ACM--字符串--Two Substrings--水的相关文章

ACM 字符串 题目整理

AC自动机 UVa 11468  Substring AC自动机+概率DP. 注意要补全不存在的边. 为什么要补全不存在的边呢?补全以后可以直接找到状态的转移,即从所有子节点就可以实现所有状态转移. #include<iostream> #include<vector> #include<cmath> #include<map> #include<algorithm> #include<cstring> #include<cst

【好好补题,因为没准题目还会再出第三遍!!】ACM字符串-组合数学(官方题解是数位DP来写)

ACM字符串 1.长度不能超过n 2.字符串中仅包含大写字母 3.生成的字符串必须包含字符串“ACM”,ACM字符串要求连在一块! ok,是不是很简单?现在告诉你n的值,你来告诉我这样的字符串有多少个 输入 输入一个正整数T,代表有T组数据 接下来T行,每行一个正整数n,n<=10. 输出 输出符合条件的字符串的数目 样例输入 1 3 样例输出 1 做题过程: 熬了三四个小时,WA了无数次!最终推出了组合数的公式! 首先暴力打表,嘿嘿!这样极大地压缩计算时间! 打表如下: 一:生成连续的7位绝对

ACM字符串输入问题

坑死了..竟然被这个问题困扰了大半个学期,今天搜来翻去终于弄明白了一些,以后固定用这几种用法好了不然总出错QAQ实际测试例子就没放了,死记这里就够用了T-T 概念: gets()函数:用来从标准输入设备(键盘)读取字符串直到换行符结束. cin 可以连续从键盘读取想要的数据,以空格.tab或换行作为分隔符. scanf("%s",str) 可以连续从键盘读取想要的字符串(数组),以空格.tab或换行作为分隔符. 基本用法: C语言:读入一段带空格的字符串使用gets()        

ACM:SCU 4437 Carries - 水题

SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Practice Description Carries frog has nn integers a1,a2,…,ana1,a2,…,an, and she wants to add them pairwise. Unfortunately, frog is somehow afraid of carries (进位). S

HDU ACM 2054 A == B ? 水题

分析:水题,主要是要注意几个细节. #include<iostream> using namespace std; char a[100005],A[100005]; char b[100005],B[100005]; void Process(char* p,int count,char* p2) { int pos; bool is_real; int i=0,k=0,j; label: while(*(p+i)!='\0' && *(p+i)=='0') i++; if(

HDU 4821 String 字符串hash(水

题意: 给定整数M L 一个字符串s 我们定义一个子串为"好"串 iff 1.长度为 M*L 2.把这个好串分成M段,每段长度为L,且每段各不相同. 且我们得到的这些好串不重复计算(即把这些好串去重) 问有几个好串 #include <stdio.h> #include <cstring> #include <iostream> #include <map> using namespace std; typedef unsigned lo

HDU ACM 2521 反素数 水题+因子打表

分析:水题,不解释. #include<iostream> using namespace std; int cnt[6000]; void init() //打表 { int i,j; memset(cnt,0,sizeof(cnt)); cnt[1]=1; //1只有他本身 for(i=2;i<=5005;i++) { cnt[i]+=2; //1和他本身 for(j=2;j<=i/2;j++) if(i%j==0) cnt[i]++; } } int main() { int

POJ3981 字符串替换【水题】

字符串替换 Description 编写一个C程序实现将字符串中的所有"you"替换成"we" Input 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 Output 对于输入的每一行,输出替换后的字符串 Sample Input you are what you do Sample Output we are what we do 问题链接:POJ3981 字符串替换 问题描述:(略) 问题分析: ????这个是一个字符串处理问题,

HDU ACM 1031 Design T-Shirt 水题

分析:给你n个人M件衣服, 选出前K件衣服评价最大值,注意要输出的是编号,编号从大到小.两次排序即可. #include<iostream> #include<algorithm> using namespace std; struct node { double m; int id; }; bool cmp(const node& a,const node& b) { if(a.m!=b.m) return a.m>b.m; else return a.id

字符串期间的水题柱

---恢复内容开始--- 在看了网上无数的模板后 还是觉得刘汝佳的最亲民: p1364,一道low到不行不能再low的trie树模板题,目的大概就是为了诱惑你敲一遍模板,把输入存在trie里,输出sz+1即可: p1361,一道low到不行的kmp模板题,ps:辣鸡到不行的我原本用trie没过,然后改用kmp(在交我的kmp代码的时候我甚至以为这题的kmp也会炸,正在脑补ac自动机的解法:)循环+kmp就好了 p1366,一道ac自动机的模板题(不知道t了多少次才知道数组的第一维表示的不是深度,