-->
当前位置:首页 > 题库

PROGRAMMING:Sequence segmentation

Luz5年前 (2021-05-10)题库402
Given an integer sequence, the longest consecutive integer sequence in the sequence is calculated as a segment. How many segments are there in the sequence?
###Input format:
The first line of input contains an integer n, which represents the number of integers in the sequence.
The second line contains n integers $$a_{ 1}$$, $$a_{ 2}$$, …, $$a_{ n} $$, denotes a given sequence of numbers, separated by a space between adjacent integers.
###Output format:
Output an integer, indicating that the given sequence has multiple segments.
###Input example:
```in
eight
8 8 8 0 12 12 8 0
```
###Output example:
```out
five
```
###Example description:
8 is the first segment, 0 is the second segment, 12 is the third segment, the penultimate integer 8 is the fourth segment, and the last 0 is the fifth segment.
  
###Scale and convention of evaluation case:
1 ≤ n ≤ 1000,0 ≤ $$a_{ i}$$≤ 1000。< br>





answer:If there is no answer, please comment