首页 > 代码库 > CCF_201409-1_相邻数对

CCF_201409-1_相邻数对

水。

 

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){    int n,a[1005];    cin >> n;    for(int i = 1;i <= n;i++)   cin >> a[i];    sort(a+1,a+n+1);    int num = 0;    for(int i = 1;i < n;i++)    {        if(a[i+1]-a[i] == 1)    num++;    }    cout << num << endl;    return 0;}

 

CCF_201409-1_相邻数对