In the below code there are 3 inputs.
First line of input is the number of testcases for which the program will run where (1<=testcases<=10) and i
is an int
.
For each testcase
Second and third input will be a String
where (1<=Stringlength<=10^5)
Output
Now for the output we need to compare both the strings and remove similar characters from both them. The output will be based on which string encounters 0 length first. if none of them is 0 after completion then it will be a draw.
Time of execution is 1.0 sec for each input but my time for 10^5 strings is 2.0. Is there a way to increase its efficiency based on the time.
import java.io.*;
import java.util.*;
public class MyProg{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of testcases");
String ts=br.readLine();
int testcase=Integer.parseInt(ts);
for(int i=0;i<testcase;i++)
{
System.out.println("Enter the 2 strings");
String sa=br.readLine().replaceAll("\\s+", "");
String sb=br.readLine().replaceAll("\\s+", "");
List<Character> s1 = new ArrayList<Character>();
List<Character> s2 = new ArrayList<Character>();
for(char c : sa.toCharArray())
s1.add(c);
for(char c : sb.toCharArray())
s2.add(c);
for(char c:s2)
{
s1.remove((Character)c);
}
for(char c:sa.toCharArray())
{
s2.remove((Character)c);
}
if(s1.size()==0 && s2.size()>0)
System.out.println("You lose some.");
else if(s1.size()>0 && s2.size()==0)
System.out.println("You win some.");
else
System.out.println("You draw some.");
}
}}