#include <iostream>
#include<math.h>
#include<map>
using namespace std;
int a[1001][1001];//定义在main()的外面,这样任何函数都有可以调用,就不需要再往其他函数中传参了
//用来遍历一个点附近八个点
int dir[8][2] = { 1,0, -1,0, 0,1, 0,-1, 1,1, -1,-1, 1,-1, -1,1 };
int n, m;
int tol;
map<int ,int> s;//用来记录一个像素点出现的次数,map中value为int类型时默认初始值为0
//判断是否为突出点
bool check(int x,int y) {//a行b列
for (int i = 0;i < 8;i++) {
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if (xx >= 0 && xx < n&&yy >= 0 && yy < m&&abs(a[x][y] - a[xx][yy]) <= tol)
return false;
}
return true;
}
int main()
{
int count = 0;
int hang, lie;
int color;
cin >> m >> n >> tol;
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) {
cin >> a[i][j];
s[a[i][j]]++;
}
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) {
if (check(i,j)&&s[a[i][j]]==1) {
count++;
hang = i, lie = j, color = a[i][j];
}
}
}
if (count == 1) {
cout << "(" << lie+1 << ", " << hang+1 << "): " << color;
}
else if (count > 1) {
cout << "Not Unique";
}
else {
cout << "Not Exist";
}
return 0;
}
参考博客:https://blog.csdn.net/qq_34594236/article/details/63692920