自己写的,感觉做的很一般,但是0ms,注意数组并不是所谓最大20,我开的100,否则会Runtime Error。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    int length,count;//count计数最后输出值
    int p_element[100];
    int r_position[100];//存储右括号在string中的位置

    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int s_element[100]={0};
        scanf("%d",&length);
        for(int j=0;j<length;j++)
        {
            scanf("%d",&p_element[j]);
            r_position[j]=j+p_element[j];
            s_element[r_position[j]]=1;
        }
        for(int p=0;p<length;p++)
        {
            count=1;
            for(int q=r_position[p]-1;q>=0;q--)
            {
                if(-1==s_element[q])
                {
                    count++;
                }
                else if(0==s_element[q])
                {
                    s_element[q]=-1;
                    printf("%d ",count);
                    break;
                }
            }
        }
        printf("\n");
    }

    return 0;
}

 

相关文章:

  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-02-03
  • 2021-05-24
  • 2021-12-21
猜你喜欢
  • 2021-12-19
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2021-08-23
相关资源
相似解决方案