题解 | #图像相似度#
图像相似度
http://www.nowcoder.com/practice/f2952ee3bb5c48a9be6c261e29dd1092
int main()
{
int m = 0;
int n = 0;
int x = 0;
double count = 0.0;//计数:相同像素个数
int arr1[100][100] = { 0 };
int arr2[100][100] = { 0 };
scanf("%d %d", &m, &n);//获取m和n
for (int i = 0; i < m; i++)//获取第一个像素阵列
{
for (int j = 0; j < n; j++)
{
scanf("%d", &arr1[i][j]);
}
}
for (int i = 0; i < m; i++)//获取第二个像素阵列
{
for (int j = 0; j < n; j++)
{
scanf("%d", &arr2[i][j]);
}
}
for (int i = 0; i < m; i++)//在这两个像素阵列中找相同的,count计数
{
for (int j = 0; j < n; j++)
{
if (arr1[i][j] == arr2[i][j])
{
count++;
}
}
}
printf("%.2lf", count*100 / (m * n));//*100是打印成百分比形式
return 0;
}