#89. 检查数字2的相邻性

    ID: 89 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp1循环结构条件结构

检查数字2的相邻性

Check Adjacency of Twos

Background

Congcong has been studying the properties of number sequences recently. He noticed that when certain numbers appear in a sequence, they always like to be next to another identical number. He wants your help to verify a specific rule.

Problem Description

Given an array of integers, return true if every 22 that appears in the array is next to another 22; otherwise, return false.

Input Format

Input is given from standard input in the following format.

A single line containing several integers, representing the elements of the array.

Output Format

Output is printed to standard output in the following format.

Output true if the condition is met, otherwise output false.

Sample

4 2 2 3
true
2 2 4
true
2 2 4 2
false

Sample Explanation

  • Sample 1: In the array [4 2 2 3], there are two 22s, and they are adjacent, so true is returned.
  • Sample 2: In the array [2 2 4], there are two 22s, and they are adjacent, so true is returned.
  • Sample 3: In the array [2 2 4 2], there are three 22s. The first two 22s are adjacent, but the last 22 is next to a 44 and not another 22, so false is returned.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.