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
| import java.util.*; public class Main { public static void main(String args[]) { Scanner input = new Scanner(System.in); while(input.hasNext()) { boolean yn = false; int n = input.nextInt(); int t = 0; String str = input.nextLine(); char ch[] = str.toCharArray();
ch[0] = 'a'; ch[ch.length - 1] = 'a'; for(int i = 0; i < ch.length; i++) { if(ch[i] == ' ') { if(ch[i + 1] == ch[i - 1]) { yn = true; t++; } } }
if(yn == true && t == n - 1) { System.out.println("Yes"); } else { System.out.println("No"); } } } }
|