#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
int s[maxn];
int main(){
int n,ans = 0;
scanf("%d",&n);
while(n--){
int x;
scanf("%d",&x);
s[x] = 1;
}
for(int i = 1;i < maxn;++i)
if(s[i] && s[i - 1]) ans++;
printf("%d\n",ans);
return 0;
}

本文展示了一个使用C++实现的简单算法,该算法通过读取一系列整数并存储在一个数组中,然后遍历数组检查相邻元素是否同时存在,以此来统计特定条件下的配对数量。代码使用了标准输入输出,并利用了C++标准库的功能。
416

被折叠的 条评论
为什么被折叠?



