PTA A_1101 Quick Sort
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805366343188480解:
递推法
#include <stdio.h>
int nums;
int l_max;
int r_min;
int candi;
int main(void)
{
int i, n, count = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", nums + i);
l_max = nums;
r_min = nums;
for (i = 1; i < n; i++)
l_max = (nums > l_max) ? nums : l_max;
for (i = n - 2; i >= 0; i--)
r_min = (nums < r_min) ? nums : r_min;
for (i = 0; i < n; i++)
if ((nums == l_max) && (nums == r_min))
candi = nums;
printf("%d\n", count);
for (i = 0; i < count; i++)
{
printf("%d", candi);
if (i + 1 < count)
putchar(' ');
}
putchar('\n');
return 0;
}
页:
[1]