Wednesday, 22 February 2017

A Task

QUESTION DESCRIPTION :

A task is given to 3 persons to complete it within a particular time. If the person exceeds the time limit he will be disqualified . Only those who complete it within the given time limit is qualified. Among the qualified persons. the person who complete the task first will be rewarded.Write a C program to find the person who is rewarded.

Input Format:

First Input corresponds to the time limit for the task in hours . Second, third and fourth input corresponds to the number of hours taken by the first, second and third persons respectively to complete the task.

Output format:

Display the person who completes first.


TEST CASE 1
 
INPUT

10 5 4 7

OUTPUT

Second person wins!!


TEST CASE 2

INPUT

4 9 6 7

OUTPUT

No person wins!!


EXPLANATION :

The code requires you check for the time taken by 3 people to complete a task and find out who won the competition by comparing the time taken by them ( the person with the least time wins ) . But if the best time is > than the disqualification time , then all the 3 people are disqualified .

The input format is 4 integers representing the time limit and the time taken by the 3 people to complete the tasks.


ALGORITHM :

  • Input 4 integers from the user ( r , a , b , c )
  • Check weather first person has won ( r>a&&a<b&&a<c )
  • Check weather second person has won ( r>b&&b<a&&b<c )
  • Check weather third person has won ( r>c&&c<a&&c<b )
  • According to the winner , print the correct output
  • If no one wins ( all conditions fail ) , print No person wins!!
# Note :  r is the max time alloted , a,b,c are the values of the time taken by person 1,2,3 respectively
SOLUTION : (Please use this as reference only)
CODE
 

No comments:

Post a Comment