Repository navigation
Expand file tree
/
Copy pathCodechef.java
More file actions
70 lines (63 loc) · 1.83 KB
/
Copy pathCodechef.java
File metadata and controls
70 lines (63 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* package codechef; // don't place package name! */
import java.util.*;
/* 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
{
String finall="";
Scanner sc= new Scanner(System.in);
System.out.println("Enter Number of cases: ");
int cases=sc.nextInt(),t=0;
String s1="",s2="";
for(int i=0;i<cases;i++)
{
System.out.println("Enter your Actual word");
if(t==0)
{
String in=sc.nextLine().toUpperCase();
t=1;
}
String inp=sc.nextLine().toUpperCase();
System.out.println("Enter your guessed Word");
String gu=sc.nextLine().toUpperCase();
String check="";
int c1=inp.length(),c2=gu.length();
s1=inp;
s2=gu;
if(c1==c2)
{
for(int j=0;j<inp.length();j++)
{
if(inp.charAt(j)==(gu.charAt(j)))
{
check=check+"G";
}
else
{
check=check+"B";
}
}
finall=finall+check+'*';
check="";
}
else
{
System.out.println("Length of words isn't same !!!");
}
}
String prt="";
for(int i=0;i<finall.length();i++)
{
if(finall.charAt(i)!='*')
{
prt=prt+finall.charAt(i);
}
else
{
System.out.println(prt);
prt="";
}
}
}
}