laisheng


私信TA

用户名:laisheng

访问量:1351

签 名:

等  级
排  名 1123
经  验 3066
参赛次数 0
文章发表 19
年  龄 0
在职情况 学生
学  校 xidian
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:下面的代码可以在我的VC上跑,不知道为啥平台上面跑不了,有无兄弟看一下啥原因

参考代码:

#include<stdio.h>

#include<malloc.h>

int main()

{

    int n,i,j,cloth_nums,cloth_location,num = 0;

    int *a1,*a2;

    scanf("%d",&n);

    a1 = (int*)malloc(sizeof(int)*(n+1));

    for(i = 0;i<n+1;i++)

    {

        a1[i] = 0;

    }

    while(scanf("%d",&cloth_nums)!=EOF)

    {

        a2 = (int*)malloc(sizeof(int)*cloth_nums);

        for(i = 0;i<cloth_nums;i++)

        {

            scanf("%d",&a2[i]);

        }

        scanf("%d",&cloth_location);

        num = 0;

        for(i = 0;i<cloth_nums;i++)

        {

            for(j=1;j<=a2[i];j++)

            {

                a1[num] = 1;

                num++;

            }

            

            a1[num] = 2;

            num++;

        }

        printf("%d\n",a1[cloth_location-1]);

        for(i = 0;i<n+1;i++)

        {

            a1[i] = 0;

        }

        free(a2);

    }

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区