NYOJ 1163 cakes(自己想复杂了)

来源:互联网 发布:传承网络 编辑:程序博客网 时间:2024/06/05 00:58

cakes

时间限制:1000 ms  |  内存限制:65535 KB
难度:0
描述
there are some naughty little cakes(less than 1000), each cake has a numberthey stand in plates whose number start from 0 increasing in turn . The process of waiting for being taste by small Q is very boring so they made a game .According to the serial numbers of the cake from small to large lying on a plate ,but they forgot the plates that they lying before, if they don't go back, small Q will be very angry.So, smart programmer monkey  can you help them?
输入
Multiple sets of test data
first give you a digsit the number of cakes;
then there are n digsits
输出
。。。
样例输入
44 2 1 354 3 1 2 5
样例输出
2 1 3 02 3 1 0 4
提示
maybe they are equal to others,if so ,printf the order before
来源
原创
上传者
TC_张焰



这道题自己有想复杂了,其实写个结构体,在里面定义两个变量,存进去,排序就可以了,wa了那么多次T-T

<pre name="code" class="cpp">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{    int x;    int y;}a[1050];int cmp(node e,node r){  if(e.x==r.x)  return e.y<r.y;//这里就是提示那句话    return e.x<r.x;}int main(){    int n;    while(~scanf("%d",&n))    {       for(int i=0;i<n;i++)        {            scanf("%d",&a[i].x);            a[i].y=i;        }        sort(a,a+n,cmp);        for(int i=0;i<n;i++)        {            printf("%d ",a[i].y);        }        printf("\n");    }}




0 0