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);
}