#82. 判断值是否在相邻元素对中无处不在

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

判断值是否在相邻元素对中无处不在

Value Everywhere

Background

Dawei is designing a sequence checking system. He needs to determine if a specific value is "everywhere" in a sequence.

Problem Description

We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array.

Input Format

Input is given from standard input in the following format.

The first line contains an integer array arr and an integer val.

Output Format

Output is printed to standard output in the following format.

Output true if val is everywhere in arr; otherwise output false.

Sample

[1 2 1 3] 1
true
[1 2 1 3] 2
false
[1 2 1 3 4] 1
false

Sample Explanation

Sample 1: For array [1 2 1 3] and value 1. The adjacent pairs are (1, 2), (2, 1), (1, 3).

  • (1, 2) contains 1.
  • (2, 1) contains 1.
  • (1, 3) contains 1. All adjacent pairs contain 1, so true is returned.

Sample 2: For array [1 2 1 3] and value 2. The adjacent pairs are (1, 2), (2, 1), (1, 3).

  • (1, 2) contains 2.
  • (2, 1) contains 2.
  • (1, 3) does not contain 2. Not all adjacent pairs contain 2, so false is returned.

Sample 3: For array [1 2 1 3 4] and value 1. The adjacent pairs are (1, 2), (2, 1), (1, 3), (3, 4).

  • (3, 4) does not contain 1. Not all adjacent pairs contain 1, so false is returned.

Constraints

  • The length of the array arr, NN, satisfies 1N10001 \le N \le 1000.
  • Elements in arr and val satisfy 1000element,val1000-1000 \le \text{element}, \text{val} \le 1000.