201409-1 相邻数对

实现

#include <cstdio>
#include <algorithm>

#define MAXN 0x3ef

int nums[MAXN];

int main() {
    int num;
    scanf("%d",&num);

    for (int i = 0;i < num;++i) {
        scanf("%d",&nums[i]);
    }

    std::sort(nums, nums + num);

    int res = 0;
    for (int i = 0;i < num - 1;++i) {
        if (nums[i] + 1 == nums[i+1]) {
            ++res;
        }
    }
    printf("%d",res);
}   
posted @ 2020-08-26 11:17  amonqsq  阅读(71)  评论(0编辑  收藏  举报