山東理工大學ACM平臺題答案關於C語言 1196 排序問題
阿新 • • 發佈:2019-01-25
1 2 3 4 5 6 7 8 9 10 1 2 3 5 4 6 10 7 8 9
#include <stdio.h>
int main()
{
int a[10], loc[10];
int i, j, t;
for (i=0; i<10; i++){
scanf("%d", a+i);
loc[i] = i+1;
}
for (i=0; i<10; i++)
for (j=i+1; j<10; j++){
if (a[i] > a[j]){
t = a[i]; a[i] = a[j]; a[j] = t;
t = loc[i]; loc[i] = loc[j]; loc[j] = t;
}
}
for (i=0; i<9; i++)
printf("%d ", a[i]);
printf("%d\n", a[9]);
for (i=0; i<9; i++)
printf("%d ", loc[i]);
printf("%d\n", loc[9]);
return 0;
}