牛客OI赛制测试赛2 C 数组下标

链接:https://www.nowcoder.com/acm/contest/185/C
来源:牛客网

题目描述

给出一个数列 A,求出一个数列B.
其中Bi   表示 数列A中 Ai 右边第一个比 Ai 大的数的下标(从1开始计数),没有找到这一个下标  Bi 就为0
输出数列B

输入描述:

第一行1个数字 n (n ≤ 10000)
第二行n个数字第 i 个数字为 Ai (0 ≤ A≤ 1000000000)

输出描述:

一共一行,第 i 个数和第 i+1 个数中间用空格隔开.
示例1

输入

复制
6
3 2 6 1 1 2

输出

复制
3 3 0 6 6 0

说明

样例不用解释

$O(n^2),10000 imes 10000$枚举,看起来虽然有点险奈何常数小啊。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define LL long long
LL a[10006],n;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(a[j]>a[i])
            {
                printf("%d ",j);
                break;
            }
            if(j==n)printf("0 ");
        }
    }
    printf("0");
    return 0;
}
原文地址:https://www.cnblogs.com/rmy020718/p/9602470.html