jeudi 24 juin 2021

i tried my best to solve this problem but stilll i am unable to solve

input In the first line given an integer t ( 1 <= t <= 100 ), which is the number of test cases.

For each test case,

In the first line there will be given a positive integer n ( 1 <= n <= 10^5 ) which is the size of the lost array. In the next line there will be n - 1 intergers Xi( 0 <= Xi <= 2 ).

If, Xi = 0 , then ith element is equal to (i+1)th element of the lost array.

int main()
{
int t;
cin>>t;

while(t--)
{
    int n;
    cin>>n;

    int i,a[n];

    for(i=1;i<n;i++)
    cin>>a[i];

    for(i=1;i<n;i++)
    {
        if(a[i]==0)
        {
            a[i]=a[i+1];
            cout<<a[i]<<" ";
        }

        if(a[i]==1 && a[i]<a[i+1])
     {
        cout<<a[i]<<" ";
     }

        if(a[i]==2 && a[i]>a[i+1])
        {
            cout<<a[i];
        }


   }
}


    return 0;
     }

Aucun commentaire:

Enregistrer un commentaire