Oxygen Level

TCS Coding Question 2

Selection of MPCS exams include a fitness test which is conducted on ground. There will be a batch of 3 trainees, appearing for running test in track for 3 rounds. You need to record their oxygen level after every round. After trainee are finished with all rounds, calculate for each trainee his average oxygen level over the 3 rounds and select one with highest oxygen level as the most fit trainee. If more than one trainee attains the same highest average level, they all need to be selected.

TCS Coding Question 2 Slot 1

Display the most fit trainee (or trainees) and the highest average oxygen level.

Note:

  • The oxygen value entered should not be accepted if it is not in the range between 1 and 100.
  • If the calculated maximum average oxygen value of trainees is below 70 then declare the trainees as unfit with meaningful message as “All trainees are unfit.
  • Average Oxygen Values should be rounded.

Example 1:

  • INPUT VALUES

            95

            92

            95

            92

            90

            92

            90

            92

            90

  • OUTPUT VALUES
    • Trainee Number : 1
    • Trainee Number : 3

 

Note:

Input should be 9 integer values representing oxygen levels entered in order as

 

Round 1

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen value of trainee 3

 

Round 2

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen value of trainee 3

 

Round 3

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen value of trainee 3

 

Output must be in given format as in above example. For any wrong input final output should display “INVALID INPUT”

18 comments on “Oxygen Level”


  • anandkumarcse101

    #include
    #include
    int main()
    {
    int x,y,z,a,b,c,k,l,m;
    float t1,t2,t3,max;
    //round-1
    scanf(“%d”,&x);
    scanf(“%d”,&y);
    scanf(“%d”,&z);
    //round-2
    scanf(“%d”,&a);
    scanf(“%d”,&b);
    scanf(“%d”,&c);
    //round-3
    scanf(“%d”,&k);
    scanf(“%d”,&l);
    scanf(“%d”,&m);
    //Value between 1 to 100
    if((x>=1&&x=1&&y=1&&z=1&&a=1&&b=1&&c=1&&k=1&&l=1&&m<=100))
    { //Calculating average
    t1=round(x+y+z)/3.0;
    printf("t1:%f\n",t1);
    t2=round(a+b+c)/3.0;
    printf("t2:%f\n",t2);
    t3=round(k+l+m)/3.0;
    printf("t3:%f\n",t3);
    //checking if average less than 70
    if(t1<70&&t2<70&&t3t2&&t1>t3)?t1:(t2>t3?t2:t3);
    if (t1==max)
    {
    printf(“Trainees Number:1\n”);
    }
    if(t2==max)
    {
    printf(“Trainees Number:2\n”);
    }
    if(t3==max)
    {
    printf(“Trainees Number:3\n”);
    }

    }
    }
    else{
    printf(“Invalid Input”);
    }
    return 0;}


  • Geetha

    R1=[int(input()) for _ in range(3)]
    R2=[int(input()) for _ in range(3)]
    R3=[int(input()) for _ in range(3)]
    Res=[]
    for i in zip(R1,R2,R3):
    Res.append(sum(i)/3)
    A=max(Res)
    if Res[0]==A:
    print(“Trainee 1”)
    if Res[1]==A:
    print(“Trainee 2”)
    if Res[2]==A:
    print(“Trainee 3”)


  • 18-564

    #include
    int main()
    {
    int n,max=0,a[100],i,sum=0;
    scanf(“%d”,&n);
    for(i=1;i<=n;i++)
    {
    scanf("%d",&a[i]);
    if( a[i]100)
    {
    printf(“oxy value out of range”);
    printf(“it must be in this 100>=n>=1 range!”);
    return 0;
    }
    sum=sum+a[i];
    }
    for(i=1;imax)
    max=a[i];
    }
    if(sum/n < 70)
    printf("All trainees are unfit\n");
    else
    {
    for(i=1;i<=n;i++)
    {
    if(a[i]==max)
    {
    printf("Trainee Number : %d\n",i);
    }

    }
    }
    return 0;
    }


  • 18-564

    #include
    int main()
    {
    int n,max=0,a[100],i,sum=0;
    scanf(“%d”,&n);
    for(i=1;i<=n;i++)
    {
    scanf("%d",&a[i]);
    if( a[i]100)
    {
    printf(“oxy value out of range”);
    printf(“it must be in this 100>=n>=1 range!”);
    return 0;
    }
    sum=sum+a[i];
    }
    for(i=1;imax)
    max=a[i];
    }
    if(sum/n < 70)
    printf("All trainees are unfit\n");
    else
    { int k=1;
    for(i=1;i<=n;i++)
    {
    if(a[i]==max)
    {
    printf("Trainee Number : %d\n",i);
    }

    }
    }
    return 0;
    }


  • Siddhartha

    Correct Me if anything is wrong
    list1 = input().split(‘,’)
    sum = 0
    list = []
    for i in list1:
    list.append(int(i))
    for i in list:
    sum += i

    avg = round(sum/len(list))

    for i in range(0,len(list)):
    if list[i]>(avg):
    print(“Trainee Number”, i+1)

    Output:
    95, 92, 95, 92, 90, 92, 90, 92, 90
    Trainee Number 1
    Trainee Number 3


  • Balaram

    sum1=sum2=sum3=0
    for j in range(0,3):
    for i in range(0,3):
    b = int(input())
    if i == 0:
    sum1 = sum1+b
    elif i == 1:
    sum2 = sum2+b
    elif i == 2:
    sum3 = sum3+b
    if sum1 > sum2 and sum1 > sum3:
    print(“Trainee Number : 1”)
    elif sum2 > sum1 and sum2 > sum3:
    print(“Trainee Number : 2”)
    elif sum3 > sum1 and sum3 > sum2:
    print(“Trainee Number : 3”)
    elif sum1 == sum2 != sum3:
    print(“Trainee Number : 1”)
    print(“Trainee Number : 2”)
    elif sum1 != sum2 == sum3:
    print(“Trainee Number : 2”)
    print(“Trainee Number : 3”)
    elif sum1 == sum3 != sum2:
    print(“Trainee Number : 1”)
    print(“Trainee Number : 3”)
    elif sum1 == sum2 == sum3:
    print(“Trainee Number : 1”)
    print(“Trainee Number : 2”)
    print(“Trainee Number : 3”)

    a better python code


  • Suvendu kumar

    #Code Here
    def MaxOxyLevel(lst):
    max_level = []
    for i in range(3):
    avg = (lst[i]+lst[i+3]+lst[i+6])/3
    max_level.append(int(avg))
    avg = 0
    item = max(max_level)
    a = [i for i, x in enumerate(max_level) if x == item]
    for i in a:
    print(“Trainee :”+str(i+1))

    #Driver Code
    oxygen = list(map(int, input().strip().split()))[:9]
    MaxOxyLevel(oxygen)


  • Suvendu kumar

    def MaxOxyLevel(lst):
    max_level = []
    for i in range(3):
    avg = (lst[i]+lst[i+3]+lst[i+6])/3
    max_level.append(int(avg))
    avg = 0
    item = max(max_level)
    a = [i for i, x in enumerate(max_level) if x == item]
    for i in a:
    print(“Trainee :”+str(i+1))

    # input from user
    oxygen = list(map(int, input().strip().split()))[:9]
    MaxOxyLevel(oxygen)


  • Tcs

    Code in python:
    lst=[]
    for i in range(9):
    n=int(input())
    if(n>0 and n<=100):
    lst.append(n)
    else:
    print("Invalid Input")
    a=lst[0]+lst[3]+lst[6]/3
    b=lst[1]+lst[4]+lst[7]/3
    c=lst[2]+lst[5]+lst[8]/3
    lst1=[a,b,c] ##[90,98,70]
    if(max(lst1)<70):
    print("trianees are unfit")
    else:
    for i in range(len(lst1)):
    if(lst1[i]==max(lst1)):
    print("Trainer Number:{}".format(i+1))


  • Shahla

    #include
    using namespace std;

    int main() {

    int a1=0,a2=0,a3=0 ;

    int a,b,c;
    for(int i=0;i>a>>b>>c;

    if(a>=1 && a=1 && b=1 && c<=100) a3+=c;

    }

    // cout<<a1<<" "<<a2<<" "<<a3<<endl;
    int maxi= max(a1,max(a2,a3));

    if(maxi/3 < 70)
    cout<<"All trainees are unfit\n";

    else
    {
    if(maxi==a1)
    cout<<"Trainee Number : 1"<<endl;
    if(maxi==a2)
    cout<<"Trainee Number : 2"<<endl;
    if(maxi==a3)
    cout<<"Trainee Number : 3"<<endl;
    }

    return 0;
    }