1 solutions
-
0
#include <stdio.h>
int main(void) { int n; scanf("%d", &n);
const int MAXV = 10000; int exist[MAXV + 1] = {0}; // 下标 0..10000 for (int i = 0; i < n; i++) { int x; scanf("%d", &x); exist[x] = 1; // 标记这个值出现 } int cnt = 0; // 对每个 x,看 x+1 是否也存在 for (int x = 0; x < MAXV; x++) { // 0..9999 if (exist[x] && exist[x + 1]) { cnt++; } } printf("%d\n", cnt); return 0;}
Information
- ID
- 68
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- # Submissions
- 61
- Accepted
- 37
- Uploaded By