#87. 连续三数奇偶性判断

    ID: 87 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp1循环结构数学基础

连续三数奇偶性判断

Consecutive Parity

Background

Congcong is currently studying the properties of number sequences. He wants to determine if an integer array contains three consecutive numbers that all share the same parity.

Problem Description

Given an array of integers, return true if the array contains either three consecutive even values or three consecutive odd values; otherwise, return false.

Input Format

The input is given from standard input in the following format.

The input consists of a single line containing space-separated integers, representing the array.

Output Format

Output to standard output in the following format.

Output a single line: true if the array contains three consecutive even or three consecutive odd values, and false otherwise.

Sample

2 1 3 5
true
2 1 2 5
false
2 4 2 5
true

Sample Explanation

Sample 1: The array is [2 1 3 5]. The numbers 1, 3, 5 are three consecutive odd numbers, so it returns true.

Sample 2: The array is [2 1 2 5]. There are no three consecutive even numbers, nor three consecutive odd numbers, so it returns false.

Sample 3: The array is [2 4 2 5]. The numbers 2, 4, 2 are three consecutive even numbers, so it returns true.

Constraints

The length of the array NN satisfies 1N10001 \le N \le 1000. Each element AiA_i in the array satisfies 0Ai1090 \le A_i \le 10^9. Time limit: 1 second, Memory limit: 1024 MB.