考題日期:2016/05/24
題號:11942
星等:1
語言:C++
題目:
題意:
判斷伐木工是否以由長到短,或以由短到長的順序排成一列。不會有人的鬍子一樣長。
程式:
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int test;
    int p[10];
    cin>>test;
    cout<<"Lumberjacks:"<<endl;
   for(int i = 0 ; i < test ; i++)
   {
        bool key = true;
        for(int j = 0 ; j < 10 ; j++)
        {
            cin>>p[j];
        }
        if(p[1]>p[2])
        {
            for(int j = 0 ; j < 9 ; j++)
            {
                if(p[j]<p[j+1])
                    key = false;
            }
        }
         if(p[1]<p[2])
        {
            for(int j = 0 ; j < 9 ; j++)
            {
                if(p[j]>p[j+1])
                    key = false;
            }
        }
        if(key)
            cout<<"Ordered"<<endl;
        else
            cout<<"Unordered"<<endl;
        
   }
   return 0;
}
測資: