Huawei Machine Test-Choose 2 people from 5 persons as etiquette

Source: Internet
Author: User

To choose 2 people from 5 persons as a courtesy, each of whom has a height range of 160-190, requiring a minimum height difference of 2 persons

(If the difference is the same, select the highest of the two) to output the height of two people in ascending order.


Sample input:161 189 167 172 188

Sample output:188 189


#include <stdio.h> #include <stdlib.h>int cmp (const void *a,const void *b) {    return * (int*) a-* (int*) b;} int main (int argc, char *argv[]) {    int a[5];    for (int i=0;i<5;++i)        scanf ("%d", &a[i]);    Qsort (a,5,sizeof (int), CMP);    int diff=30;    int index=0;    for (int i=0;i<4;++i)    {        if (A[i+1]-a[i]<=diff)        {            index=i;            Diff=a[i+1]-a[i];        }    }    printf ("%d%d\n", a[index],a[index+1]);    return 0;}

The test data is: 161 189 167 172 188

The result is:


Huawei Machine Test-Choose 2 people from 5 persons as etiquette

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.