ZCMU-4950: 数组排序-看不懂题意题

ZCMU-4950: 数组排序-看不懂题意题

题目链接:https://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=4950

Description
输入一个数组的值,求出各个值从小到大排序后的次序。

Input
输入有多组数据。
每组输入的第一个数为数组的长度n(1<=n<=10000),后面的数为数组中的值,以空格分割。

Output
各输入的值按从小到大排列的次序(最后一个数字后面没有空格)。

Sample Input
1
68
15
1 70 25 79 59 63 65 6 46 82 28 62 92 96 43
Sample Output
1
1 11 3 12 7 9 10 2 6 13 4 8 14 15 5

思路。先说题意吧,就是询问原来的数组第i个元素在排好序数组的那个位置
好了,这就是次序,读懂题意得可以去写了,感觉太水可以去下面复制了。
下面AC代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int n;
    while(~scanf("%d",&n))
    {
    
    

    int a[n],b[n];
    for(int i = 0;i<n;i++)
    {
    
    
        scanf("%d",&a[i]);
        b[i] = a[i];
    }

    sort(b,b+n);
    int ok = 0;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<n;j++)
        {
    
    
            if(a[i]==b[j])
            {
    
    
                if(ok) printf(" ");
               printf("%d",j+1);
               ok = 1;
               break;
            }
        }
        puts("");
    }

    return 0;
}

其实我本来想用vector,因为有find可以用,也可以直接赋值。
—别问我如果有重复会发现输出次序相同的问题,因为这题没要求,所以可以AC,如果追求精益求精,那么可以加vis数组解决。—

猜你喜欢

转载自blog.csdn.net/eatkeyborad/article/details/115031490
今日推荐