Friday, July 21, 2017

Uva problem solution 11942 - Lumberjack Sequencing

problem linK:

Discuss: just simply check the array twice. if any of them are ordered then print ordered.otherwise print unordered.

try yourself before see the code



#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,t;
    cin >>t;
    for(i=0;i<t;i++)
    {
        int ara[12],cnt=0,flag=0;
        for(j=0;j<10;j++)
        {
            cin >>ara[j];
        }
        if(i==0)
            cout <<"Lumberjacks:"<<endl;
        for(j=0;j<9;j++)
        {
            if(ara[j]<ara[j+1])
                cnt=1;
            if(ara[j]>ara[j+1])
                flag=1;
        }
        if((cnt==1&&flag==0)||(cnt==0&&flag==1))
            cout <<"Ordered"<<endl;
        else
            cout <<"Unordered"<<endl;
    }
    return 0;
}

No comments:

Post a Comment