Solution of 11942 Lumberjack Sequencing- UVA
please do not copy it rather watch it for learning purpose :)
Here is the code :-
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//MECHABOO
bool smallToBig(int arr[]);
bool bigToSmall(int arr[]);
int main(){
int test;
cin >> test;
for(int i=0;i<test;i++)
{
int arr[10];
bool nat;
for(int j=0;j<10;j++)
{
cin >> arr[j];
}
if(arr[0]>arr[1]||arr[1]>arr[2])
{
nat=bigToSmall(arr);
}
if(arr[0]<arr[1]||arr[1]<arr[2])
{
nat=smallToBig(arr);
}
if(i==0) cout << "Lumberjacks:"<<endl;
if(nat) cout << "Ordered"<<endl;
else cout << "Unordered"<<endl;
}
//MECHABOO
return 0;
}
bool smallToBig(int arr[])
{
bool adi=true;
for(int i=0;i<9;i++)
{
if(arr[i]<arr[i+1]) adi=true;
else return false;
}
return adi;
}
bool bigToSmall(int arr[])
{
bool adi=true;
for(int i=0;i<9;i++)
{
if(arr[i]>arr[i+1]) adi=true;
else return false;
}
return adi;
}
If you do not understand please leave a message here.
or mail us mechaboo786@gmail.com
or you can leave a message at fb . Link :- https://www.facebook.com/mechaboo/
please do not copy it rather watch it for learning purpose :)
Here is the code :-
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//MECHABOO
bool smallToBig(int arr[]);
bool bigToSmall(int arr[]);
int main(){
int test;
cin >> test;
for(int i=0;i<test;i++)
{
int arr[10];
bool nat;
for(int j=0;j<10;j++)
{
cin >> arr[j];
}
if(arr[0]>arr[1]||arr[1]>arr[2])
{
nat=bigToSmall(arr);
}
if(arr[0]<arr[1]||arr[1]<arr[2])
{
nat=smallToBig(arr);
}
if(i==0) cout << "Lumberjacks:"<<endl;
if(nat) cout << "Ordered"<<endl;
else cout << "Unordered"<<endl;
}
//MECHABOO
return 0;
}
bool smallToBig(int arr[])
{
bool adi=true;
for(int i=0;i<9;i++)
{
if(arr[i]<arr[i+1]) adi=true;
else return false;
}
return adi;
}
bool bigToSmall(int arr[])
{
bool adi=true;
for(int i=0;i<9;i++)
{
if(arr[i]>arr[i+1]) adi=true;
else return false;
}
return adi;
}
If you do not understand please leave a message here.
or mail us mechaboo786@gmail.com
or you can leave a message at fb . Link :- https://www.facebook.com/mechaboo/
Comments
Post a Comment