救救孩子,不知道哪里错了,哪位大佬帮看看呀~
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n= scanner.nextInt(); Map<Integer, Long> map = new HashMap<>(); long ans = 0; for (int i=0;i<n;i++){ int x = scanner.nextInt(); int y = scanner.nextInt(); int x1 = y-x, x2 = x+y; if(map.containsKey(x1)){ ans+=map.get(x1); } if(map.containsKey(x2)){ ans+=map.get(x2); } map.put(x1, map.getOrDefault(x1, 0L)+1); map.put(x2, map.getOrDefault(x2, 0L)+1); } System.out.println(ans); } }
全部评论
(8) 回帖