即使身堕地狱,也要心怀整个天堂。
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
分析:
开一个比较大的数组 然后遍历整个数组排序能比较好且快的解决问题
源代码:
#include <iostream>
using namespace std;
int main()
{
int a[1000]= {0};
int n,t=0;
for(int i=1; i<=10; i++)
{
cin>>n;
a[n]=i;
}
for(int i=0; i<1000; i++)
if(a[i]!=0)
{
if(t!=0) cout<<" ";
cout<<i;
t++;
}
cout<<endl;
t=0;
for(int i=0; i<1000; i++)
if(a[i]!=0)
{
if(t!=0) cout<<" ";
cout<<a[i];
t++;
}
return 0;
}