Given n different integers, ask how many of these numbers are integers, and their values are exactly 1 (CCF real problem)

Source: Internet
Author: User

CCF Certification Exam September 2014 The first question describes a given n different integers, asking how many of these numbers are integers, and their values are exactly 1. Input format the first line of input contains an integer n, representing the number of given integers.
The second line contains the n integers given. Output format outputs an integer that represents the number of pairs that have a value that is exactly 1 apart. Sample Input 6
10 2 6 3 7 8 Sample Output 3 example shows that the number of pairs with a value of exactly 1 is (2, 3), (6, 7), (7, 8). Evaluation use case size and convention 1<=n<=1000, the given integer is a non-negative integer that does not exceed 10000.

#include <iostream>
using namespace Std;


int n,array[10000];


void Chuli (int a[10000])
{
int count=0;
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
if (a[i]==a[j]+1| | A[I]==A[J]-1)
{
Count+=1;
}
}
}
cout<<count<<endl;
}


int main ()
{
cin>>n;
for (int i=0;i<n;i++)
{
cin>>array[i];
}
Chuli (array);
return 0;
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Given n different integers, ask how many of these numbers are integers, and their values are exactly 1 (CCF real problem)

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.