In this Qualify the round problem we have a coding contest, there are two types of problems one is the list of easy problems, which are worth 1 point each. and second is a list of hard problems, which are worth 2 points each.
To qualify for the next round, a contestant must score at least X points. A man solved x easy problems and y hard problems. we need to check will the man qualifies or not?
Let's say man solved 10 easy problems and 2 hard problems. so his total score is 10.1 + 2.2 = 14. and he needs at least 15 points to qualify, which he has and hance he qualifies the round.
Problem solution in C programming.
#include <stdio.h>
int main()
{
int t,x,a,b,y;
scanf("%d",&t);
while(t--)
{
scanf("%d\n%d\n%d\n",&x, &a,&b);
y=a+(2*b);
if(x<=y)
{
printf("Qualify\n");
}
else
{
printf("NotQualify\n");
}
}
return 0;
}Here in the above code in the while loop in each and every test can we check if the value of y = a+(2*b) where y= total number of scores, a = easy problems, and b = hard problems is greater than or equal to the x (where x is the minimum number of score need to qualify). then man will qualify the round and we will print Qualify. otherwise, we will print not qualify as an output screen.
Problem solution in C++ programming.
#include <iostream>
using namespace std;
int main() {
int t,x,a,b;
cin>>t;
while(t--)
{
cin>>x>>a>>b;
if(a*1+b*2>=x)
{
cout<<"qualify"<<endl;
}
else
{
cout<<"notqualify"<<endl;
}
}
return 0;
}Problem solution in Java programming.
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 scan = new Scanner(System.in);
int testCase = scan.nextInt();
for(int i = 0; i < testCase; i++){
int total = scan.nextInt();
int x = scan.nextInt();
int y = scan.nextInt();
System.out.println(totalPoints(x,y,total));
}
}
public static String totalPoints(int x, int y, int total){
if(total <= ((x*1) + (y*2))){
return "Qualify";
}else{
return "NotQualify";
}
}
}Problem solution in Python programming.
x=int(input())
for i in range(x):
a,b,c=input().split()
if int(b)*1 + int(c)*2 >=int(a):
print("Qualify")
else:
print("NotQualify")Here in the above code in the for loop, we check if the value of b + c*2 is greater than or equal to a then we will print the Qualify as an output message. otherwise, we will print not qualify as an output. here we need to know that we will be converting all the values to an integer using the int() function.

0 Comments