简单的数学题,还是挺好玩的
#include <stdio.h>
int main()
{
int N;
while (scanf("%d", &N), N > 0)
{
getchar();
char type = getchar();
int num[50];
for (int i = 0; i < N; i++)
{
scanf("%d", &num[i]);
}
int result[50] = {0};
if (type == 'P')
{
for (int i = 0; i < N - 1; i++)
{
for (int j = i + 1; j < N; j++)
{
if (num[i] > num[j])
{
result[num[j] - 1] ++;
}
}
}
}
else
{
for (int i = 0; i < N; i++)
{
int j = 0;
for (int k = 0; j < N; j++)
{
if (result[j] == 0)
{
if (k == num[i])
{
break;
}
else
{
k++;
}
}
}
result[j] = i + 1;
}
}
for (int i = 0; i < N; i++)
{
if (i > 0)
{
printf(" ");
}
printf("%d", result[i]);
}
printf("\n");
}
return 0;
}