经典方法:
#include<stdio.h>
#include<stdlib.h>
int min(int* A, int start, int end)
{
if (start == end)
return A[start];
else
{
int min1, min2, mid;
mid = (start + end) / 2;
min1 = min(A,start, mid);
min2 = min(A,mid + 1, end);
if (min1 < min2)
return min1;
else
return min2;
}
}
void Lv(int* b, int* a, int min, int num)
{
for (int i = 0,k = 0; k < num;i++)
{
if (a[i] != min)
{
b[k++] = a[i];
}
}
}
int main()
{
int n,min0=0,max0;
int a[100], b[100];
scanf("%d", &n);
int m;
scanf("%d", &m);
/*int* a = (int*)malloc(m * sizeof(int));*/
//a[m]
int target;
scanf("%d", &target);
while (n--)
{
for (int i = 0; i < m; i++)
{
scanf("%d", &a[i]);
}
int j=m,n; //此处定义为了不让m受到影响
for (int i = 1,n=j; i <= target; i++)
{
min0 = min(a, 0, --n); //定义n的意义是如果也用--j会使下面的Lv函数受到影响(看了三遍才找出的错误)
Lv(a, a, min0, --j); //定义j的原因是直接--m会使m的值发生改变,影响第二遍遍历(看了两遍找出的错误)
}
/*max0 = max(a, 0, m - 1);*/
printf("%d\n",min0);
}
/*free(a);*/
return 0;
}
|