Pro.ID1524 TitleSimple Sort Title链接http://10.20.2.8/oj/exercise/problem?problem_id=1524 AC13 Submit13 Ratio100.00% 时间&空间限制描述Sorting is a basic function in any databases. Assume there are N entries in the given database. Every entry has M items. To determine the order, we are first required to provide the priorities among the columns. Priorities are measured by Mdistinct integers. The lower integer indicates the higher priority. To compare two entries, item in the column with highest priority is used. If equal, the items in the column with the second highest priority are compared. Then the 3rd to N-th highest column, until in which the items are not equal. If two entries are completely the same, the one given earlier in the data will rank first. You are now given a job to implement the sorting function with different column priorities. 输入The first integer T ( ≤ 30 ) indicates the number of cases. There follows T cases. In every cases, the first line contain two integer N ( ≤ 100 ), M ( ≤ 10 ). N is the number of entries. M is the number of the column. The N lines is followed, every line contains M integers. The j-th integer in the i-th line correspond with the content in the i-th entry j-th column. Then a number Q ( ≤ 10 ) follows indicating the number of the queries. In every line, there are M integers. The i-th number is the priority of the i-th column. 输出Description Sorting is a basic function in any databases. Assume there are N entries in the given database. Every entry has M items. To determine the order, we are first required to provide the priorities among the columns. Priorities are measured by Mdistinct integers. The lower integer indicates the higher priority. To compare two entries, item in the column with highest priority is used. If equal, the items in the column with the second highest priority are compared. Then the 3rd to N-th highest column, until in which the items are not equal. If two entries are completely the same, the one given earlier in the data will rank first. You are now given a job to implement the sorting function with different column priorities. Input The first integer T ( ≤ 30 ) indicates the number of cases. There follows T cases. In every cases, the first line contain two integer N ( ≤ 100 ), M ( ≤ 10 ). N is the number of entries. M is the number of the column. The N lines is followed, every line contains M integers. The j-th integer in the i-th line correspond with the content in the i-th entry j-th column. Then a number Q ( ≤ 10 ) follows indicating the number of the queries. In every line, there are M integers. The i-th number is the priority of the i-th column. Output For every case, output Q lines. Every line contains N distinct integers (numbered from 0 to N-1) in ascending order with given priorities. Number i means the (i+1)-th entry. Sample Input 1 Sample Output 0 1 3 2 4 5 样例输入1 样例输出0 1 3 2 4 5 提示作者 |