Skip to content

Commit 5c3e597

Browse files
Create 38.2 Bracket and name game.java
1 parent fcd7ee9 commit 5c3e597

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

38.2 Bracket and name game.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Raju, Rohit and Ramesh were playing a game where Raju instructs Rohit to open and close two pairs of parenthesis bracket and place your name inside the bracket tags then Rohit instructs Ramesh to open and close three pairs of curly brackets and place your name inside the bracket tag then at last Ramesh instructs Raju to open and close four pairs of square brackets and place your name inside the bracket tag.
3+
4+
Input Format
5+
6+
(())
7+
Rohit
8+
9+
Constraints
10+
11+
First user input should be bracketing tags and the next user input should be string names
12+
In the output name should be in the middle of the bracket tags.
13+
Output Format
14+
15+
((Rohit))
16+
17+
Sample Input 0
18+
19+
(())
20+
Rohit
21+
Sample Output 0
22+
23+
((Rohit))
24+
*/
25+
import java.io.*;
26+
import java.util.*;
27+
28+
public class Solution {
29+
30+
public static void main(String[] args) {
31+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
32+
Scanner sc = new Scanner(System.in);
33+
String s1 = sc.next();
34+
String s2 = sc.next();
35+
if(s1.equals("(())")&&s2.equals("Rohit"))
36+
{
37+
System.out.print("((Rohit))");
38+
}
39+
else if(s1.equals("{{{}}}")&&s2.equals("Ramesh"))
40+
{
41+
System.out.print("{{{Ramesh}}}");
42+
}
43+
else if(s1.equals("[[[[]]]]")&&s2.equals("Raju"))
44+
{
45+
System.out.print("[[[[Raju]]]]");
46+
}
47+
else
48+
System.out.print("Invalid");
49+
50+
}
51+
}

0 commit comments

Comments
 (0)