forked from MiYazJE/Acepta-el-reto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p188.java
66 lines (36 loc) · 933 Bytes
/
p188.java
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
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class p188 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String linea;
String[] palabras = new String[20];
String cad1 = "";
String cad2 = "";
boolean encadenando;
while(s.hasNext()) {
encadenando = false;
linea = s.nextLine();
palabras = linea.split(" ");
if(palabras.length <= 1) {
System.out.println("SI");
} else {
for(int i=0; i<palabras.length-1; i++) {
cad1 = palabras[i].substring(palabras[i].length() - 2);
cad2 = palabras[i+1].substring(0, 2);
if(cad1.equals(cad2)) {
encadenando = true;
} else {
encadenando = false;
break;
}
}
if(encadenando == true) {
System.out.println("SI");
} else {
System.out.println("NO");
}
}
}
s.close();
}
}