题目大意:给你一个两个字符组成的字符串作为密码,以及一系列的两个字符组成的字符串集合。问用这些集合中的字符串能不能组成一个含有密码字符串的字符串。
题目分析:因为长度都相同且只有二个字符。暴力即可。
具体上是只有两种情况,第一种就是集合中有和密码完全相同的字符。第二种是有两个字符串组成密码(可以是同一个字符串)。
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
//#define mod 1030
#define size 3
using namespace std;
typedef long long LL;
const int maxn = (LL)1e5 + 100;
const int maxm = 50000;
const LL inf = (LL)6 * LL(1e18);
const double eps = 1e-8;
char ori[3], par[110][3];
int main() {
while (scanf("%s", ori) == 1) {
int n;
bool flag = false;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", par[i]);
if (strcmp(ori, par[i]) == 0) flag = true;
}
if (flag) {
printf("YES\n");
continue;
}
for (int i = 0; i < n; i++) {
if (ori[0] != par[i][1]) continue;
int k = i;
for (int j = 0; j < n; j++) {
//if (k == j) continue;
if (ori[1] == par[j][0]) {
flag = true;
break;
}
}
if (flag) break;
}
printf("%s\n", flag ? "YES" : "NO");
}
}