Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
codeforces 868 A. Bark to Unlock(水)
题意:所有字符串都是两个小写字母组成,先给一个密码字符串,然后给N种字符串,可以选择任意种、任意数量的字符串拼成一个字符串,如果能包含密码则输出YES。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 char s[5], s1[5]; 6 int n; 7 int main() { 8 bool i = 0, j = 0, f = 0; 9 scanf("%s %d", s, &n); 10 while(n--) { 11 scanf("%s", s1); 12 if(f) continue; 13 if(s[0] == s1[0] && s[1] == s1[1]) f = 1; 14 else { 15 if(s1[1] == s[0]) i = 1; 16 if(s1[0] == s[1]) j = 1; 17 f = i & j; 18 } 19 } 20 printf("%s\n", f?"YES":"NO"); 21 return 0; 22 }