BC79
图像相似度
http://www.nowcoder.com/questionTerminal/f2952ee3bb5c48a9be6c261e29dd1092
题目要求是相似度,没必要开二维数组,直接初始化长度为长乘宽的一维数组即可,我们只需要把两个数组都比较一遍,然后统计出有多少相同的数字,最后计算出百分比,结束。
#include <iostream>
#include <iomanip>
using namespace std;
int pic1[10001];
int pic2[10001];
int main(){
int a, b, c;
double count = 0;
cin >> a >> b;
c = a * b;
for(int t = 0; t < c; t++){
cin >> pic1[t];
}
for(int t = 0; t < c; t++){
cin >> pic2[t];
count += pic2[t] == pic1[t] ? 1: 0;
}
cout << fixed << setprecision(2) << count * 100.00 / c;
return 0;
}
查看6道真题和解析