TCS Examination EXAMTIME Solution
Two friends, Dragon and Sloth, are writing a computer science examination series. There are three subjects in this series: DSA, TOC, and DM. Each subject carries 100 marks.
You know the individual scores of both Dragon and Sloth in all 3 subjects. You have to determine who got a better rank.
The rank is decided as follows:
- The person with a bigger total score gets a better rank
- If the total scores are tied, the person who scored higher in DSA gets a better rank
- If the total score and the DSA score are tied, the person who scored higher in TOC gets a better rank
- If everything is tied, they get the same rank.
Input Format
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains three space-separated integers denoting the scores of Dragon in DSA, TOC and DM respectively.
- The second line of each test case contains three space-separated integers denoting the scores of Sloth in DSA, TOC and DM respectively.
Output Format
- For each test case, if Dragon got a better rank then output
"Dragon"
, else if Sloth got a better rank then output"Sloth"
. If there was a tie then output"Tie"
. Note that the string you output should not contain quotes. - The output is case insensitive. For example, If the output is “Tie” then “TiE”, “tiE”, “tie”, etc are also considered correct.
Constraints
- 1≤T≤1000
- Each score of both Dragon and Sloth lies between 0 and 100.
Subtasks
Subtask #1 (100 points): Original constraints
Sample Input 1
4
10 20 30
30 20 10
5 23 87
5 23 87
0 15 100
100 5 5
50 50 50
50 49 51
Sample Output 1
SLOTH
TIE
DRAGON
DRAGON
Explanation
- For the first test case, Sloth and Dragon have the same total score but Sloth gets a better rank because he has a higher score in DSA.
- For the second test case, Sloth and Dragon have the same rank because they have the same score among all subjects.
- For the third test case, Dragon gets a better rank because he has a greater total score.
- For the fourth test case, Sloth and Dragon have the same total score and same DSA score. Dragon gets a better rank because he has a greater TOC score.
SOLUTION
Program: TCS Examination EXAMTIME Solution in C++
#include <iostream>
using namespace std;
int main() {
int t;
cin >>t;
for(int i=0;i<t;i++)
{
int x,y,z;
int a,b,c;
cin >>x>>y>>z;
cin >>a>>b>>c;
if((x+y+z)>(a+b+c))
{
cout <<"Dragon"<<"\n";
}
else if((a+b+c)>(x+y+z))
{
cout<<"Sloth"<<"\n";
}
else if((x+y+z)==(a+b+c))
{
if(x>a)
{
cout<<"Dragon"<<"\n";
}
else if(x<a)
{
cout<<"Sloth"<<"\n";
}
else
{
if(y>b){cout<<"Dragon"<<"\n";}
else if(y<b){cout<<"Sloth"<<"\n";}
else{cout<<"Tie"<<"\n";}
}
}
}
return 0;
}
Program: TCS Examination EXAMTIME Solution in Java
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int dd = sc.nextInt();
int dt = sc.nextInt();
int ddm = sc.nextInt();
int sd = sc.nextInt();
int st = sc.nextInt();
int sdm = sc.nextInt();
int dragon = dd+dt+ddm;
int sloth = sd+st+sdm;
if(dragon > sloth){
System.out.println("DRAGON");
}
else if(sloth > dragon){
System.out.println("SLOTH");
}
else if(dragon == sloth && dd>sd){
System.out.println("DRAGON");
}
else if(dragon == sloth && sd>dd){
System.out.println("SLOTH");
}
else if(dragon == sloth && dd == sd && dt>st){
System.out.println("DRAGON");
}
else if(dragon == sloth && dd == sd && st>dt){
System.out.println("SLOTH");
}
else {
System.out.println("TIE");
}
}
}
}
Program: TCS Examination EXAMTIME Solution in Python
for _ in range(int(input())):
d = list(map(int,input().split()))
s = list(map(int,input().split()))
if sum(d)<sum(s):
print("sloth")
elif sum(d)>sum(s):
print("dragon")
else:
f = 0
for i in range(3):
if d[i]<s[i]:
print("sloth")
break
elif d[i]>s[i]:
print("dragon")
break
else:
f+=1
if f==3:
print("tie")