1#include <stdio.h>2 3 intMain ()4 {5 inti,j,k;6 intT,n;//T: number of data groups N: The number of rows per row in each set of data7 inta[2][8];//two rows of data in each set of data that is used to store input8 intTemp//Intermediate temporary variable in the process for sorting each row of data9 intSum//used to record the sum of the product of two rows of dataTen Onescanf"%d", &t);//number of input data groups A - for(i=t;i>0; i--)//grouping input and processing - { thesum=0;//Clear 0 Product and - -scanf"%d", &n);//Enter the number of rows per row in two rows of data - + for(j=0;j<2; j + +)//enter two rows of data - for(k=0; k<n;k++) +scanf"%d",&a[j][k]); A at /*********************************************************************** - * * To achieve the minimum product, you only need to find the two rows of data not multiplied by the maximum and the minimum value multiplication, - * * Then add, so the two rows of data are sorted in descending and ascending order - ***********************************************************************/ - for(j=0; j<n-1; j + +)//Sort Two rows of data in descending order and ascending order by using bubble Sort method - for(k=j+1; k<n;k++) in { - if(a[0][k]>a[0][J])//Descending to { +temp=a[0][j]; -a[0][j]=a[0][k]; thea[0][k]=temp; * } $ if(a[1][k]<a[1][J])//AscendingPanax Notoginseng { -temp=a[1][j]; thea[1][j]=a[1][k]; +a[1][k]=temp; A } the } + - for(j=0; j<n;j++)//multiply the elements of the same subscript in two rows of data, and then add and Sum $sum+=a[0][j]*a[1][j]; $ -printf"%d\n", sum);//output minimum product and - } the - return 0;Wuyi}
Minimum product (basic type)