CSP-201409-1-相邻数对
解题代码
#include <iostream>
#include <vector>
using namespace std;
vector<int>arr;
int num;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int t;
cin >> t;
for (const auto& it : arr)
{
if (abs(t - it) == 1)
{
num++;
}
}
arr.push_back(t);
}
cout << num;
return 0;
}