AtCoder - abc230_b
题意:
一个字符串T有n多个oxx组成,输入字符串S,判断S是否为T的子串
这介绍两种方法,枚举和调用库函数:
暴力枚举:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
ll n;
vector<pair<int,int> >line;
string t = "oxx";
char a[15];
int main()
{
string s;
cin >> s;
int f = 0;
for(int i = 0;i < 3; ++i){
for(int j = 0;j < s.size(); ++j){
a[j] = t[(i+j) % 3];
}
f |= s==a;
}
if(f) puts("Yes");
else puts("No");
return 0;
}
调用库:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "oxxoxxoxxoxxoxxoxx";
string b;
cin >> b;
string::size_type idx;
idx=a.find(b);//在a中查找b.
//cout << idx << '\n';
//cout << string::npos;
if(idx == string::npos )//不存在。
cout << "No";
else//存在。
cout <<"Yes";
}
本文介绍了AtCoder平台上的abc230_b题目,该题要求判断给定字符串S是否为特定模式的子串。文章提供了两种解决方法:一种是通过枚举的方式手动检查匹配情况;另一种则是利用标准库函数进行字符串查找。
8519

被折叠的 条评论
为什么被折叠?



