Sita shortlists 3 gifts G1, G2 and G3 priced at Rs.r1, Rs.r2 and Rs.r3 respectively.
She wants to buy 1 of these gifts to present to her dad on his retirement day.
She loves him the most and wants to buy the most expensive of these 3 gifts. She also wants to make sure that the gift is not damaged.
Can you please help her?

Input Format:
Input consists of 3 integers that correspond to r1, r2, and r3. The next input is a string that is either G1, G2, G3 or NONE. If this input is G1, then G1 is damaged. (Similarly for G2 and G3). If this input is NONE, none of the gifts are damaged.
Output Format:
The output consists of a string that corresponds to the gift that Sita selects for her dad.

Sample Input :
20
30
10
G1
Sample Output :
G2


Program Code:
#include<stdio.h>
#include<string.h>
int main()
{
    int r1,r2,r3,max=0;
    char c[2];
   scanf("%d%d%d%s",&r1,&r2,&r3,c);
   
    if(strcmp(c,"G1")==0)
    {
    max=r2>r3?r2:r3;
    if(max==r2)printf("G2");
    else
    printf("G3");
    }
    if(strcmp(c,"G2")==0)
    {
    max=r1>r3?r1:r3;
    if(max==r1)printf("G1");
    else
    printf("G3");
    }
    if(strcmp(c,"G3")==0)
    {
    max=r1>r2?r1:r2;
    if(max==r1)printf("G1");
    else
    printf("G2");
    }
    
   if(strcmp(c,"NONE")==0)
    {
    printf("none of the gifts are damaged");
    }
    return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: