数组其中有多少个数,恰好等于集合中另外两个(不同的)数之和?
import java.io.IOException; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count = 0; int res = 1; int arr1[] = new int[100010]; int arr2[] = new int[100010]; for (int i = 1; i <= n; i++) { arr1[i] = sc.nextInt(); } for (int i = 1; i < n; i++) { for (int j = i + 1; j <= n; j++) { arr2[res++] = arr1[i] + arr1[j]; } } for (int i = 1; i <= n; i++){ for (int j = 1; j <= res; j++){ if (arr2[j] == arr1[i]){ count++; break; } } } System.out.println(count); } }