已经把输入搭建起来了,但实在没想到怎么做

img


麻烦按照我的代码继续写下去,尽量简单易懂一点,t h x csdnimg.cn/release/static/image/mid/ask/5045905

运行结果:

img

代码:

#include <iostream>
using namespace std;

//排序
void Sort(int a[], int b[], int n)
{
    int i, j, t;
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - 1 - i; j++)
        {
            if (a[j] > a[j + 1])
            {
                t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
                //交换B
                t = b[j];
                b[j] = b[j + 1];
                b[j + 1] = t;
            }
        }
    }
}



int main()
{
    int T, n;
    cin >> T;
    for (int i = 0; i < T; i++)
    {
        cin >> n; //学生数
        int* a = new int[n];
        int* b = new int[n];
        int a1, b1;
        for (int j = 0; j < n; j++)
        {
            cin >> a1 >> b1;
        }
        //排序
        Sort(a, b, n);
        int ri = 0;
        for (int j = 0; j < n; j++)
        {
            if (b[j] > ri)
            {
                if (j == 0)
                {
                    cout << a[j];
                    ri = a[j] + 1;
                }
                else
                {
                    if (a[j] > ri)
                    {
                        cout << a[j];
                        ri++;
                    }
                    else
                    {
                        cout << ri;
                        ri++;
                    }

                }
            }
            else
                cout << "0";

            if (j < n - 1)
                cout << " ";
            else
                cout << endl;
        }

        delete[] a; delete[] b;
        a = 0; b = 0;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int result[100]={0};
    int n;cin>>n;
    int mem[100]={0};
    int i,j,l,r,t=0,k=1,num;
    for (i=1;i<=n;i++)
    {
        t=0;
        cin>>num;
        mem[i]=num;
        for (j=1;j<=num;j++)
        {
            cin>>l>>r;
            if (t>=l&&t<=r)
            {
                result[k]=t;
                k++;
                t++;continue;
            }
            if (t<l)
            {
                result[k]=l;
                k++;
                t=l+1;
                continue;
            }
            if (t>r)
            {
                result[k]=0;
                k++;
            }
        }
    }
    k=1;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=mem[i];j++)
        {
            cout<<result[k]<<' ';
            k++;
        }
        cout<<endl;
    }
}


您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632