排序问题

来源:互联网 发布:java socket通信原理 编辑:程序博客网 时间:2024/06/05 08:30

Time Limit: 1000MS Memory limit: 65536K

题目描述

输入10个整数,将它们从小到大排序后输出,并给出现在每个元素在原来序列中的位置。

输入

输入数据有一行,包含10个整数,用空格分开。

输出

输出数据有两行,第一行为排序后的序列,第二行为排序后各个元素在原来序列中的位置。

示例输入

1 2 3 5 4 6 8 9 10 7

示例输出

1 2 3 4 5 6 7 8 9 101 2 3 5 4 6 10 7 8 9
#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;struct N{    int m;    int n;} p[10];int cmp(N q,N w){    return q.m<w.m;}int main(){    while(scanf("%d",&p[0].m)!=EOF)    {        for(int i=1; i<10; i++)        {            scanf("%d",&p[i].m);        }        int j=1;        for(int i=0; i<10; i++)        {           p[i].n=j;             j++;        }        sort(p,p+10,cmp);        for(int k=0; k<9; k++)        {            printf("%d ",p[k].m);        }        printf("%d\n",p[9].m);        for(int k=0; k<9; k++)        {            printf("%d ",p[k].n);        }        printf("%d\n",p[9].n);    }    return 0;}

0 0