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)
t=[0,0,0]
res=[]
v,j,k,nc=0,0,0,0
while(k<=8):
olevel=int(input())
if(1<olevel<=100):
t[v]=t[v]+olevel
j+=1
if(j==3):
t[v]=t[v]//3
v+=1
j=0
else:
print("Enter valid input")
olevel=int(input())
if(100<olevel or olevel<1):
nc+=1
if(nc==1):
k-=1
nc=0
k+=1
r=t
m=max(t)
for i in r:
if(i==m):
ind=r.index(i)
res.append(ind+1)
r[ind]=0
m=max(r)
ind=r.index(i)
res.append(ind+1)
for i in res:
print("Trainee Number: ",i,end="\n")
// simple code in java
Scanner sc=new Scanner(System.in);
int t1=0,t2=0,t3=0,n=1;
while(n=1)&&(k<=100))
{
if(n%3==1) {
t1+=k;
n++;
}
else if(n%3==2)
{
t2+=k;
n++;
}
else
{
t3+=k;
n++;
}
}
else n++;
}
t1=t1/3;
t2=t2/3;
t3=t3/3;
if(t1<70 && t2<70 && t3<70) System.out.println("all trainees are unfit");
else
{
int ans=Math.max(Math.max(t1, t2),t3);
if(ans==t1) System.out.println("t1 is fit");
if (ans==t2) System.out.println("t2 is fit");
if(ans==t3) System.out.println("t3 is fit");
}
while(n<10)
{
int k=sc.nextInt();
if((k=100))
}
matrix=[]
for i in range(3):
a=[]
for j in range(3):
a.append(int(input()))
matrix.append(a)
sum1,sum2,sum3=0,0,0
for i in range(3):
for j in range(3):
if j==0:
sum1=sum1+matrix[i][j]
if j==1:
sum2=sum2+matrix[i][j]
if j==2:
sum3=sum3+matrix[i][j]
x=[]
x.append(sum1//3)
x.append(sum2//3)
x.append(sum3//3)
if x[0]<70 or x[1]<70 or x[2]=x[1] and x[0]>=x[2]:
print(“trainee 1”)
if x[1]>=x[2] and x[1]>=x[0]:
print(“trainee 2”)
if x[2]>=x[0] and x[2]>=x[1]:
print(“trainee 3”)
#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”)
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);
}
}
}
}
}