CCF认证真题-(201409-1)-相邻数对

it2022-05-05  109

1 #include <iostream> 2 #include <algorithm> 3 #include <set> 4 using namespace std; 5 int arr[1005]; 6 7 int main() 8 { 9 ios::sync_with_stdio(false); 10 cin.tie(0); 11 int n; 12 cin >> n; 13 for (int i = 0; i < n; i++) 14 cin >> arr[i]; 15 sort(arr, arr + n); 16 int ans = 0; 17 for (int i = 1; i < n; i++) 18 if (arr[i] - arr[i - 1] == 1) 19 ans++; 20 cout << ans << endl; 21 return 0; 22 }

 

转载于:https://www.cnblogs.com/AntonLiu/p/11163766.html


最新回复(0)