BETTEROPT(Allot Table)
Problem link -LINK
Author- Aagam Jain
Tester - Aman Gupta
Difficulty : Simple
Problem Tag : Implementation , String
Problem :
If a string only have “tea!” in their sentence then print “SERVE TEA”.
If a string only have “coffee!” in their sentence then print “SERVE COFFEE”.
If a string only have"beer!" in their sentence then print “SERVE BEER”.
Else print “DO NOT UNDERSTAND”.
Explanation :
Simple brute force approach use find or compare function of strings to solve this out.
My Solutions :
JAVA solution
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 tc=sc.nextInt();
String s=sc.nextLine();
while(tc-->0)
{
s=sc.nextLine();
boolean t=(s.contains("tea!"));
boolean c=(s.contains("coffee!"));
boolean b=(s.contains("beer!"));
if(t & !c & !b)
System.out.println("SERVE TEA");
else if(!t & c & !b)
System.out.println("SERVE COFFEE");
else if(!t & !c & b)
System.out.println("SERVE BEER");
else
System.out.println("DO NOT UNDERSTAND");
}
}
}
C++ Solution
LINK