Codeforces Round #306 (Div. 2) A. Two Substrings string两个函数使用
2017-10-26 16:22
357 查看
C++ 中 string 的 find 函数 和 reverse 函数的使用
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;
typedef long long ll;
const int maxn = 10000 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;
string s;
int main() {
cin >> s;
int len = (int) s.size();
if(len < 4) return 0*puts("NO");
string t = s;
reverse(t.begin(), t.end()); // void
string t1 = "AB", t2 = "BA";
int p1 = s.find(t1), p2 = t.find(t1);
//cout << p1 << " == " << p2 << endl;
if( p1 >= 0 && p2 >= 0 && p1+p2+4 <= len) return 0*puts("YES");
p1 = s.find(t2), p2 = t.find(t2);
if( p1 >= 0 && p2 >= 0 && p1+p2+4 <= len) return 0*puts("YES");
return 0*puts("NO");
}
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;
typedef long long ll;
const int maxn = 10000 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;
string s;
int main() {
cin >> s;
int len = (int) s.size();
if(len < 4) return 0*puts("NO");
string t = s;
reverse(t.begin(), t.end()); // void
string t1 = "AB", t2 = "BA";
int p1 = s.find(t1), p2 = t.find(t1);
//cout << p1 << " == " << p2 << endl;
if( p1 >= 0 && p2 >= 0 && p1+p2+4 <= len) return 0*puts("YES");
p1 = s.find(t2), p2 = t.find(t2);
if( p1 >= 0 && p2 >= 0 && p1+p2+4 <= len) return 0*puts("YES");
return 0*puts("NO");
}
相关文章推荐
- Codeforces Round #306 (Div. 2) D-E
- Codeforces Round #306 (Div. 2) D.E. 解题报告
- Codeforces Round #306 (Div. 2) A
- Codeforces Round #306 (Div. 2)D
- Codeforces Round #306 (Div. 2), problem: (A) Two Substrings
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad (状态压缩)
- Codeforces Round #306 (Div. 2), problem: (A) Two Substrings
- Codeforces Round #306 (Div. 2) -- E. Brackets in Implications
- Codeforces Round #306 (Div. 2)
- Codeforces Round #306 (Div. 2) C
- Codeforces Round #306 (Div. 2)
- Codeforces Round #306 (Div. 2) B DFS
- Codeforces Round #306 (Div. 2) A B C
- Codeforces Round #306 (Div. 2)B. Preparing Olympiad--状态压缩
- Codeforces Round #306 (Div. 2) 550D - Regular Bridge 构造图
- Codeforces Round #459 (Div. 2) B. Radio Station STL map的使用
- 【Codeforces Round 262 (Div 2)E】【爆搜 估价函数剪枝 搜索步长剪枝】Roland and Rose 整格放点 点对欧几里得距离平方和尽可能大
- Codeforces Round #306 (Div. 2) ABCDE(构造)
- Codeforces Round #306 (Div. 2)
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad