PAT 甲級 A1009 (2019/02/01)
阿新 • • 發佈:2019-02-22
span nbsp spa can color print product main scan
1 #include<cstdio> 2 struct Poly{ 3 int exp; //次數 4 double coe; //系數 5 }A[1001]; 6 double Product[2001]; 7 int main(){ 8 int n1, n2, count = 0; 9 scanf("%d",&n1); 10 for(int i = 0; i < n1; i++){ 11 scanf("%d %lf", &A[i].exp, &A[i].coe);12 } 13 scanf("%d",&n2); 14 for(int i = 0; i < n2; i++){ 15 int Temp_exp; 16 double Temp_coe; 17 scanf("%d %lf", &Temp_exp, &Temp_coe); 18 for(int i = 0; i < n1; i++){ 19 if(A[i].coe != 0){ 20 Product[A[i].exp + Temp_exp] +=(A[i].coe * Temp_coe);21 } 22 } 23 } 24 for(int i = 0; i <= 2000; i++){ 25 if(Product[i] != 0.0) { 26 count++; 27 } 28 } 29 printf("%d",count); 30 for(int i = 2000; i >= 0; i--){ 31 if(Product[i] != 0.0) { 32 printf("%d %.1f", i, Product[i]); 33 } 34 } 35 return 0; 36 }
PAT 甲級 A1009 (2019/02/01)