排序问题
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
输入10个整数,将它们从小到大排序后输出,并给出现在每个元素在原来序列中的位置。
Input
输入数据有一行,包含10个整数,用空格分开。
Output
输出数据有两行,第一行为排序后的序列,第二行为排序后各个元素在原来序列中的位置。
Sample Input
1 2 3 5 4 6 8 9 10 7
Sample Output
1 2 3 4 5 6 7 8 9 10 1 2 3 5 4 6 10 7 8 9
Hint
Source
#include<stdio.h>
int main(){
int a[10];
int b[10];
int i,j;
int temp,m;
for(i=0;i<10;i++){
scanf("%d",&a[i]);
b[i]=i+1;
}
for(i=0;i<10-1;i++){
for(j=i+1;j<10;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
m=b[i];
b[i]=b[j];
b[j]=m;
}
}
}
for(i=0;i<10;i++){
if(i==0){
printf("%d",a[i]);
}else{
printf(" %d",a[i]);
}
}
printf("\n");
for(i=0;i<10;i++){
if(i==0){
printf("%d",b[i]);
}else{
printf(" %d",b[i]);
}
}
printf("\n");
}