[Problem-solving report] 11942 - Lumberjack Sequencing

Subject to the effect

Original title: http://uva.onlinejudge.org/external/119/11942.pdf

background:

 
There is a foreman with a group of lumberjacks, loggers foreman liked to find their trouble, he will ask a group of ten loggers are in accordance with the length of their beards sequentially in a row.
You please write a program to determine whether loggers from long to short, or from short to long sequence in a row. Not as long as someone's beard
 
 

 

Entry

The first column has an integer N (0 <N <20) represents a set of test data, then there are N columns, each column 10 has a different length per positive integer beard.

 

Export

Please "Ordered" as expressed order to "Unordered" indicates not according to order, make a first column output "Lumberjacks:".

 

 Sample Input 

3 
13 25 39 40 55 62 68 77 88 95 
88 62 77 20 40 10 99 56 45 36 
91 78 61 59 54 49 43 33 26 18

 Sample Output 

Lumberjacks: 
Ordered 
Unordered 
Ordered

algorithm:

I speak of the algorithm is to sort digital inputs, respectively, from small to large and from large to small, the original data and then compare the result.

Code:

Here attached my code, you can go here to submit your code to verify your code is correct.

#include<stdio.h>
int main(void)
{
    int a[10],b[10],c[10];
    int n,i,j,l,k,m,swap,temp;

    scanf("%d",&n);
    printf("Lumberjacks:\n");

    while(n--)
    {

        for(i=0;i<10;i++)
        {
            b[i]=0;
            c[i]=0;
        }
        m=k=l=0;
        temp=0;
        for(i=0;i<10;i++)
        scanf("%d",&a[i]);
        for(i=0;i<10;i++)
        {
            b[i]=a[i];
            c[i]=a[i];
        }
        for(i=0;i<10;i++)
        {
            swap=0;
            for(j=0;j<9;j++)
            if(b[j]>b[j+1])
            {
                swap=1;
                temp=b[j+1];
                b[j+1]=b[j];
                b[j]=temp;
            }
            if(!swap)break;
        }
        for(i=0;i<10;i++)
        {
            l=9-i;
            c[l]=b[i];

        }
        for(i=0;i<10;i++)
        if(a[i]-b[i]==0)
            k++;
        for(i=0;i<10;i++)
        if(a[i]-c[i]==0)
            m++;


        if(k!=10&&m!=10)
        printf("Unordered\n");
        else
        printf("Ordered\n");

    }
    return 0;
}

 

 

 

Reproduced in: https: //www.cnblogs.com/qisong178878915/archive/2013/02/22/2922360.html

Guess you like

Origin blog.csdn.net/weixin_34006965/article/details/94237236
Recommended