-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeForces868A
54 lines (50 loc) · 1.15 KB
/
CodeForces868A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
public class CodeForces868A {
public static void main(String[] args) {
/*
* Create Variables based on the input Import scanner, Scanner scanner =
* system.in
* create 4 variables (int)
* create 1 variable (String)
* the string will be a scanner input
* one int will be a scanner input
* loop through the second scanner input
* create a array make that an input
* loop through the array (if)
* print YES if succeed
*/
Scanner scanner = new Scanner(System.in);
int i;
int k;
int n;
String ns;
ns = scanner.next();
n = scanner.nextInt();
String[] str = new String[n];
for (i = 0; i < n; i++) {
str[i] = scanner.next();
if (str[i].equals(ns)) {
System.out.println("YES");
return;
}
}
k = 1;
for (i = 0; i < n; i++) {
if (str[i].charAt(1) == ns.charAt(0)) {
k = 0;
break;
}
}
if (k == 1) {
System.out.println("NO");
return;
}
for (i = 0; i < n; i++) {
if (ns.charAt(1) == str[i].charAt(0)) {
System.out.println("YES");
return;
}
}
System.out.println("NO");
}
}