CSP201509-1: array segmentation, csp201509-1 Segmentation

Source: Internet
Author: User

CSP201509-1: array segmentation, csp201509-1 Segmentation

Introduction:CSPHttp://www.cspro.org/lead/application/ccf/login.jsp)YesbyChina Computer Society (CCFThe "Computer vocational qualification certification" examination is initiated to authenticate the competence of professionals in computer software development, software testing, information management, and other fields. The authenticated object is engaged in or will be engaged inITSpecialized technical and technical management personnel in the field, as well as review objects for university candidates.

 

LProblem description

Given an integer series, the same consecutive longest integer series in the series is counted as one segment. How many segments are there in the series?

LInput Format

The first line of the input contains an integer n, indicating the number of integers in the series.

The second row contains n integers a1, a2 ,..., An, indicating the given series. Adjacent integers are separated by a space.

LOutput Format

Output an integer that indicates that the given series has multiple segments.

LSample Input

8

8 8 8 0 12 8 0

LSample output

5

LExample

8 8 8 is the first segment, 0 is the second segment, 12 12 is the third segment, the second to last integer 8 is the fourth segment, and the last 0 is the fifth segment.

LScale and conventions of evaluation cases

1 ≤ n ≤ 1000, 0 ≤ ai ≤.

 

LSource code

# Include <stdio. h>

# Include <stdlib. h>

# Include <memory. h>

 

Int main (void)

{

Int n; // number

Int result = 0;

Int currentNum =-1;

Scanf ("% d", & n );

Int * input = (int *) malloc (sizeof (int) * n );

Memset (input, 0, sizeof (int) * n );

For (int I = 0; I <n; I ++)

{

Scanf ("% d", input + I );

}

For (int I = 0; I <n; I ++)

{

If (currentNum! = Input [I])

{

CurrentNum = input [I];

Result + = 1;

}

}

Printf ("% d \ n", result );

Free (input );

Return 0;

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.