/*
- 系数为0不输出
- 貌似runtime异常也显示答案不正确
*/
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); in.nextToken(); int n = (int) in.nval; int[] N = new int[n]; double[] a = new double[n]; for (int i = 0; i < n; i++) { in.nextToken(); N[i] = (int) in.nval; in.nextToken(); a[i] = in.nval; } in.nextToken(); int m = (int) in.nval; int[] M = new int[m]; double[] b = new double[m]; for (int i = 0; i < m; i++) { in.nextToken(); M[i] = (int) in.nval; in.nextToken(); b[i] = in.nval; } double[] map = new double[N[0] + M[0]+1]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { map[N[i] + M[j]] += a[i] * b[j]; } } int k = 0; for (int i = N[0] + M[0]; i >= N[n - 1] + M[m - 1]; i--) { if (Math.abs(map[i]) > 0.0001) { k++; } } System.out.print(k); for (int i = N[0] + M[0]; i >= N[n - 1] + M[m - 1]; i--) { if (Math.abs(map[i]) > 0.0001) { System.out.print(String.format(" %d %.1f", i, map[i])); } } System.out.println(); } }
标签:map,Product,PAT,int,double,Polynomials,nval,new,nextToken From: https://www.cnblogs.com/fishcanfly/p/17783421.html