题意

给一个字符串(长度<=10^5)。问当中有没有一个”BA”和一个”AB”呢?假设都有而且它们不反复(即ABA不算),输出YES。否则输出NO。

思路

一開始想简单了…..

我们扫一遍,把全部”AB”字符串中A的索引放入一个vector a,把全部”BA”字符串中B的索引放入还有一个vector b。最后扫一遍两个vector。假设发现一个b的值既不是一个a的值+1,也不是那个a的值-1,那么肯定就存在不反复的”BA”和”AB”了。

代码

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 100010;
char s[maxn];
vector<int> a;
vector<int> b;
int main()
{
scanf("%s",s);
int len = strlen(s);
bool flag1 = false;
bool flag2 = false;
for(int i = 0 ; i < len ; i ++) {
if(s[i] == 'A' && s[i+1] == 'B') {
a.push_back(i);
}
if(s[i] == 'B' && s[i+1] == 'A') {
b.push_back(i);
}
}
for(int i = 0 ; i < a.size() ; i ++) {
for(int j = 0 ; j < b.size() ; j ++) {
if(a[i]!=b[j]+1 && a[i]!=b[j]-1) {
printf("YES\n");
return 0;
}
}
}
printf("NO\n");
return 0;
}

Codeforces Round #306 (Div. 2) A的更多相关文章

  1. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  2. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  3. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  4. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  5. Codeforces Round #306 (Div. 2) D. Regular Bridge 构造

    D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  6. Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力

    C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  7. Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs

    B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...

  8. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  9. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

  10. Codeforces Round #306 (Div. 2) A B C

    题目链接:http://codeforces.com/contest/550 A 暴力一发. 代码: #include <iostream> #include <stdio.h> ...

随机推荐

  1. vue-cli的创建、基本配置和遇到的问题总结

    vue-cli的创建及基本配置 1. 创建 vue-cli 项目 确保本地安装了最新版本的nodejs环境(会自带npm环境); 全局安装vue-cli,命令:npm i -g vue-cli 创建项 ...

  2. jQuery——自定义动画

    动画方法:animate(json,1000, function (){}) 参数说明:json代表属性设置,1000是动画时间,最后一个是回调函数,其中动画时间可选 属性支持:http://www. ...

  3. CSS——轮播图中的箭头

    注意事项: 1.定位中left权重比right高,top权重比bottom高 2.两个span标签嵌套在一个盒子中,将来显示隐藏只需要控制父盒子就行了 <!DOCTYPE html> &l ...

  4. php入门学习相关函数

      1.join(): 定义和用法 join() 函数返回由数组元素组合成的字符串. join() 函数是 implode() 函数的别名. 注释:join() 函数接受两种参数顺序.但是由于历史原因 ...

  5. css的基本单词

    <border>边框 border边框 <text>文本 text文本 <indent>缩进 indent缩进 <align>对齐方式 align对齐方 ...

  6. 安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的ionic项目出现问题的解决

    安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的程序出现的问题.看错误信息,由于NodeJs版本升级导致的. 到提示的目录下运行:npm rebuild node-sass -g ...

  7. MYSQL数据库迁移到ORACLE数据库

    一.环境和需求1.环境 MySQL数据库服务器: OS version:Linux 5.3 for 64 bit mysql Server version: 5.0.45 Oracle数据库服务器: ...

  8. 前端自动化构建工具gulp使用

    1. 全局安装 gulp: $ npm install --global gulp 2. 作为项目的开发依赖(devDependencies)安装: $ npm install --save-dev ...

  9. android studio 创建第一个app之hello world

    android studio 创建第一个app之hello world 想要用studio创建一个简单的app,结果遇到各种问题,application就是允许不起来,后来在专业人的帮助下,删除了一些 ...

  10. uva253 Cube painting(UVA - 253)

    题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相 ...