第一行包含两个整数m和n,表示图像的行数和列数,用单个空格隔开。1≤m≤100, 1≤n≤100。之后m行,每行n个整数0或1,表示第一幅黑白图像上各像素点的颜色,相邻两个数用单个空格隔开。之后m行,每行n个整数0或1,表示第二幅黑白图像上各像素点的颜色,相邻两个数用单个空格隔开。
一个实数,表示相似度(以百分比的形式给出),精确到小数点后两位。
3 3 1 0 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 1
44.44
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), m = in.nextInt(); int[][] num_1 = new int[n][m]; int[][] num_2 = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { num_1[i][j] = in.nextInt(); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { num_2[i][j] = in.nextInt(); } } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (num_1[i][j] == num_2[i][j]) { count++; } } } double ret = ((count * 1.00) / (n * m)) * 100; System.out.printf("%.2f", ret); } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int m=sc.nextInt(),n=sc.nextInt(); int[][] arr1=new int[m][n],arr2=new int[m][n]; arr1=loop(arr1,m,n,sc); arr2=loop(arr2,m,n,sc); int count=0; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(arr1[i][j]==arr2[i][j]) count++; } } System.out.printf("%.2f",(float)(count*100)/(m*n)); } public static int[][] loop(int[][] arr,int m,int n,Scanner sc){ for(int i=0;i<m;i++) for(int j=0;j<n;j++){ arr[i][j]=sc.nextInt(); } return arr; } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int m = scanner.nextInt(); int n = scanner.nextInt(); int[][] Martix = new int[m][n]; //相似度 double similarity = 0.0; for(int i = 0;i < m;i++){ for(int j = 0;j < n;j++){ Martix[i][j] = scanner.nextInt(); } } for(int k = 0;k < m;k++){ for(int l = 0;l < n;l++){ //Martix[i][j] = scanner.nextInt(); //输入第二个矩阵的值,与第一个矩阵下的各个值相比,有相同数字相似度就上升 int toJudgeValueList = scanner.nextInt(); if(toJudgeValueList == Martix[k][l]){ similarity++; } } } double similarityPercents = (100.0 * similarity) / (m * n); System.out.println(String.format("%.2f",similarityPercents)); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String[] str = bufferedReader.readLine().split(" "); int line = Integer.parseInt(str[0]); int column = Integer.parseInt(str[1]); int[][] num = new int[line][column]; for (int i = 0; i < line; i++) { String[] strings = bufferedReader.readLine().split(" "); for (int j = 0; j < strings.length; j++) { int a = Integer.parseInt(strings[j]); num[i][j] = a; } } double count = 0.00; for (int i = 0; i < line; i++) { String[] strings = bufferedReader.readLine().split(" "); for (int j = 0; j < strings.length; j++) { int b = Integer.parseInt(strings[j]); if (num[i][j] == b){ count++; } } } System.out.printf("%.2f",(count*100 / (line * column))); } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ //最普通的方法 Integer m=sc.nextInt(); Integer n=sc.nextInt(); int[][]pic=new int[m][n]; double similarity=0.0; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ pic[i][j]=sc.nextInt(); } } for(int d=0;d<m;d++){ for(int g=0;g<n;g++){ if(pic[d][g]==sc.nextInt()){ similarity++; } } } System.out.printf("%.2f",100.0*similarity/(m*n)); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); List<Integer> list1 = new ArrayList<>(); List<Integer> list2 = new ArrayList<>(); while (sc.hasNextInt()) { for (int i = 0; i < m * n; i++) { list1.add(sc.nextInt()); } for (int i = 0; i < m * n; i++) { list2.add(sc.nextInt()); } double t = 0; for (int i = 0; i < m * n; i++) { if (list1.get(i) == list2.get(i)) { t++; } } System.out.printf("%.2f\n", ((t * 100) / (m * n))); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int m = scanner.nextInt(); int n = scanner.nextInt(); int[] array = new int[m*n]; int similar = 0; int num = 0; for(int i=0;i<m*n;i++) { array[i] = scanner.nextInt(); } //不必创建两个数组,另一个直接比较即可 for(int i=0;i<m*n;i++) { num = scanner.nextInt(); if(num==array[i]) { similar++; } } System.out.printf("%.2f",similar*1.0/(m*n)*100); }