Hello coders, today we are going to solve Grade The Steel CodeChef Solution whose Problem Code is FLOW014.
Task
A certain type of steel is graded according to the following conditions.
- Hardness of the steel must be greater than 50
- Carbon content of the steel must be less than 0.7
- Tensile strength must be greater than 5600
The grades awarded are as follows:
- Grade is 10 if all three conditions are met
- Grade is 9 if conditions (1) and (2) are met
- Grade is 8 if conditions (2) and (3) are met
- Grade is 7 if conditions (1) and (3) are met
- Grade is 6 if only one condition is met
- Grade is 5 if none of the three conditions are met
Write a program to display the grade of the steel, based on the values of hardness, carbon content and tensile strength of the steel, given by the user.
Input Format
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three numbers hardness, carbon content and tensile strength of the steel.
Output Format
For each test case, print Grade of the steel depending on Conditions, in a new line.
Constraints
- 1 ≤ T ≤ 1000
- 0 ≤ hardness, carbon content, tensile strength ≤ 10000
Sample Input
3
53 0.6 5602
45 0 4500
0 0 0
Sample Output
10
6
6
Solution – Grade The Steel | CodeChef Solution
C++
#include<bits/stdc++.h> using namespace std; int main(){ int t;cin>>t; while(t--){ float a,b,c; cin>>a>>b>>c; int ans; if(a>50 && b<0.7 && c>5600){ cout<<10<<endl; } else if(a>50 && b<0.7){ cout<<9<<endl; } else if(b<0.7 && c>5600){ cout<<8<<endl; } else if(a>50 && c>5600){ cout<<7<<endl; } else if(a>50 || b<0.7 || c>5600){ cout<<6<<endl; } else{ cout<<5<<endl; } } return 0; }
Python
# cook your dish here t = int(input()) for i in range(t): h, c, ts = map(float, input().split()) if((h>50) and (c<0.7) and (ts>5600)): print("10") elif((h>50) and (c<0.7)): print("9") elif((c<0.7) and (ts>5600)): print("8") elif((h>50) and (ts>5600)): print("7") elif((h>50) or (c<0.7) or (ts>5600)): print("6") else: print("5")
Java
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i<t; i++) { int h = sc.nextInt(); double c = sc.nextDouble(); int ts = sc.nextInt(); if((h>50) && (c<0.7) && (ts>5600)) { System.out.println("10"); } else if((h>50) && (c<0.7)) { System.out.println("9"); } else if((c<0.7) && (ts>5600)) { System.out.println("8"); } else if((h>50) && (ts>5600)) { System.out.println("7"); } else if((h>50) || (c<0.7) || (ts>5600)) { System.out.println("6"); } else { System.out.println("5"); } } sc.close(); } }
Disclaimer: The above Problem (Grade The Steel) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.