这题只要比较坐标的四周,然后计数就可以了。
#include <iostream>
using namespace std;int main()
{int n;cin >> n;int arr[1005][2] = { 0 };int res[5] = { 0 };int up = 0;int down = 0;int left = 0;int right = 0;int score = 0;for (int i = 0; i < n; i++){cin >> arr[i][0] >> arr[i][1];}for (int i = 0; i < n; i++){int x = arr[i][0];int y = arr[i][1];up = 0;down = 0;left = 0;right = 0;for (int j = 0; j < n; j++){if (x == arr[j][0] && y == arr[j][1] - 1){up++;}if (x == arr[j][0] && y == arr[j][1] + 1){down++;}if (x == arr[j][0]-1 && y == arr[j][1]){left++;}if (x == arr[j][0]+1 && y == arr[j][1]){right++;}}score = 0;if (up && down && left && right){for (int j = 0; j < n; j++){if ((x == arr[j][0] - 1)&& (y == arr[j][1] - 1)){score++;}if ((x == arr[j][0] + 1) && (y == arr[j][1] - 1)){score++;}if ((x == arr[j][0] - 1) &&( y == arr[j][1] + 1)){score++;}if ((x == arr[j][0] + 1) && (y == arr[j][1] + 1)){score++;}}res[score]++;}}for (int i = 0; i < 5; i++){cout << res[i] << endl;}return 0;
}