Codeforces 868 A Bark to Unlock(水题)

题目链接

题目大意:给你一个两个字符组成的字符串作为密码,以及一系列的两个字符组成的字符串集合。问用这些集合中的字符串能不能组成一个含有密码字符串的字符串。

题目分析:因为长度都相同且只有二个字符。暴力即可。

具体上是只有两种情况,第一种就是集合中有和密码完全相同的字符。第二种是有两个字符串组成密码(可以是同一个字符串)。


#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");
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值