指针用的有点少了,有点不适应
用的冒泡排序
代码如下:
#include<stdio.h>
int num[100][100];
int * p[100], jud[100];
int judge(int i, int j, int rank);
int m, n, k;
int main(void)
{
scanf("%d%d%d", &m, &n, &k);
for(int i = 0; i < k; i++)
scanf("%d", &jud[i]);
jud[k] = 1;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
scanf("%d", &num[i][j]);
p[i] = num[i];
}
//开始排序
for(int i = 0; i < m - 1; i++)
for(int j = i + 1; j < m; j++)
if(judge(i, j, 0))
{
int * tmp = p[i];
p[i] = p[j];
p[j] = tmp;
}
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if(j) putchar(' ');
printf("%d", * (p[i] + j));
}
putchar('\n');
}
return 0;
}
int judge(int i, int j, int rank)
{
if(rank > k) return 0;
if(* (p[i] + jud[rank] - 1) > * (p[j] + jud[rank] - 1))
return 1;
else if(* (p[i] + jud[rank] - 1) < * (p[j] + jud[rank] - 1))
return 0;
return judge(i, j, rank + 1);
}