#253. 数组前四位查找特定数字
数组前四位查找特定数字
Find 9 in First Four Elements
Background
Congcong is learning array operations and encountered an interesting small problem.
Problem Description
Given an array of integers, return true if one of the first 4 elements in the array is a 9. The array length may be less than 4.
Input Format
Input is given from standard input in the following format.
An array of integers, with elements separated by spaces.
Output Format
Output is printed to standard output in the following format.
Output
trueif 9 is found; otherwise, outputfalse.
Sample
[1 2 9 3 4]
true
[1 2 3 4 9]
false
[1 2 3 4 5]
false
Sample Explanation
- Sample 1: The first four elements of the array
[1, 2, 9, 3, 4]are1, 2, 9, 3. Since it contains the number 9, the output istrue. - Sample 2: The first four elements of the array
[1, 2, 3, 4, 9]are1, 2, 3, 4. Since it does not contain the number 9, the output isfalse. - Sample 3: The first four elements of the array
[1, 2, 3, 4, 5]are1, 2, 3, 4. Since it does not contain the number 9, the output isfalse.
Constraints
1s, 1024KiB for each test case.