# 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.

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”

```#include <stdio.h>
int main()
{
int trainee[3][3];
int average[3] = {0};
int i, j, max=0;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&trainee[i][j]);
if(trainee[i][j]<1 || trainee[i][j]>100)
{
trainee[i][j] = 0;
}
}
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
average[i] = average[i] + trainee[j][i];
}
average[i] = average[i] / 3;
}
for(i=0; i<3; i++) { if(average[i]>max)
{
max = average[i];
}
}
for(i=0; i<3; i++)
{
if(average[i]==max)
{
printf("Trainee Number : %d\n",i+1);
}
if(average[i]<70)
{
printf("Trainee is Unfit");
}
}
return 0;
}
```
```#include<iostream.h>
using namespace std;
int main()
{
int trainee[3][3];
int average[3] = {0};
int i, j, max=0;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++) { cin>>trainee[i][j];
if(trainee[i][j]<1 || trainee[i][j]>100)
{
trainee[i][j] = 0;
}
}
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
average[i] = average[i] + trainee[j][i];
}
average[i] = average[i] / 3;
}
for(i=0; i<3; i++) { if(average[i]>max)
{
max = average[i];
}
}
for(i=0; i<3; i++)
{
if(average[i]==max)
{
cout<<"Trainee Number : "<<i+1<<"\n";
}
if(average[i]<70)
{
cout<<"Trainee is Unfit";
}
}
return 0;
}

```
```import java.util.Scanner;
class Main {
public static void main(String[] args) {
int[][] trainee = new int[3][3];
int[] average = new int[3];
int max = 0;
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
trainee[i][j] = sc.nextInt();
if(trainee[i][j] < 1 || trainee[i][j] > 100) {
trainee[i][j] = 0;
}
}
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
average[i] = average[i] + trainee[j][i];
}
average[i] = average[i] / 3;
}
for(int i = 0; i < 3; i++) {
if(average[i] > max) {
max = average[i];
}
}
for(int i = 0; i < 3; i++) {
if(average[i] == max) {
System.out.println("Trainee Number : " + (i + 1));
}
if(average[i] <70) {
System.out.print("Trainee is Unfit");
}
}
}

}

```
```trainee = [[],[],[],[]]
for i in range(3):
for j in range(3):
trainee[i].append(int(input()))
if (trainee[i][-1]) not in range(1,101):
print("invalid input")
for i in range(3):
trainee[3].append((trainee[2][i]+trainee[1][i]+trainee[0][i])//3)
maximum = max(trainee[3])
for i in range(3):
if trainee[3][i] < 70 :
print("Trainee {0} is unfit".format(i+1))
elif trainee[3][i] == maximum:
print("Trainee Number: ",i+1)
```

### 14 comments on “Oxygen Level”

• Ajay

#simplified code in python
trainees = 3
track_round = 3
t = []
for x in range(1,4):
for y in range(1,4):
oxy_level = int(input(“enter oxygen level “))
t.append(oxy_level)
if(oxy_level in range(0,100)):
print(“oxy_level after round “,x,”of trainee”,y)
else:
print(“invalid input”)
t1 = []
t2 = []
t3 = []
t1.append(t[0])
t1.append(t[3])
t1.append(t[6])
t2.append(t[1])
t2.append(t[4])
t2.append(t[7])
t3.append(t[2])
t3.append(t[5])
t3.append(t[8])
sum1 = 0
sum2 =0
sum3 =0
for x in range(0,len(t1)):
sum1 = sum1 + t1[x]
for x in range(0,len(t2)):
sum2 = sum2 + t2[x]
for x in range(0,len(t3)):
sum3 = sum3 + t3[x]

l = [sum1,sum2,sum3]
if(sum1>=sum2 and sum1>70 and sum1>=sum3):
print(“Traninee Number : 1”)
if(sum2>=sum1 and sum2>=sum3 and sum2>70):
print(“Trainee Number : 2”)
if(sum3>=sum1 and sum3>=sum2 and sum3>70):
print(“Trainee Number : 3”)
else:
print(“All trainees are unfit”)

• Vaibhav

import java.util.*;
public class Tcs {

public static void main(String []args){

Scanner sc=new Scanner(System.in);
int a[]=new int[9];
int b[]=new int[3];
int n;
System.out.println(“enter oxygen level of 3 players of 3 rounds”);

for(int i=0;i=1&&n<=100)
a[i]=n;
else
{
System.out.println("invalid input");
return;
}
}

b[0]=(a[0]+a[3]+a[6])/3;
b[1]=(a[1]+a[4]+a[7])/3;
b[2]=(a[2]+a[5]+a[8])/3;
int max =Arrays.stream(b).max().getAsInt();
if(max<70)
System.out.println("All trainees are unfit");

else
{

for(int i=0;i<3;i++)
{
if(b[i]==max)
{

System.out.println("Trainee Number :"+(i+1)+" with oxygen level "+max);

}
}
}

}

}