-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThreeStrings_CF.java
71 lines (65 loc) · 2.75 KB
/
ThreeStrings_CF.java
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
71
package threestrings_cf;
import java.util.*;
import java.io.*;
public class ThreeStrings_CF {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int cnt = 1 , num= s.nextInt();
s.nextLine();
while(cnt<=num){
String []str1 = s.nextLine().split("");
String []str2 = s.nextLine().split("");
String []str3 = s.nextLine().split("");
int change = 0;
boolean isDisplay = false;
for(int i = 0 ; i<str1.length ; i ++){
//System.out.println(Arrays.toString(str1));
//System.out.println(Arrays.toString(str2));
if(!checkSame(str1[i],str2[i]) && !checkSame(str2[i],str3[i]) && !checkSame(str1[i],str3[i])){
toDisplay(false);
isDisplay=true;
break;
}
else if (checkSame(str1[i],str2[i]) && checkSame(str2[i],str3[i])){
change++;
//System.out.println(change);
//System.out.println("");
}
else if(!checkSame(str1[i],str2[i]) && !checkSame(str2[i],str3[i]) && checkSame(str1[i],str3[i])){
String temp = str2[i];
str2[i]=str3[i];
str3[i]=temp;
change++;
// System.out.println(change);
}
else if(!checkSame(str1[i],str2[i]) && checkSame(str2[i],str3[i]) && !checkSame(str1[i],str3[i])){
String temp = str1[i];
str1[i]=str3[i];
str3[i]=temp;
change++;
// System.out.println(change);
}
else{
toDisplay(false);
isDisplay=true;
// System.out.println(change);
break;
}
}
//System.out.println("final");
// System.out.println(change);
if(change==str1.length)
toDisplay(true);
else if(change!=str1.length && !isDisplay)
toDisplay(false);
cnt++;
}
}
public static boolean checkSame(String str1 , String str2){
return str1.equals(str2);
}
public static void toDisplay(boolean bool){
System.out.printf("%s",bool?"YES":"NO");
System.out.println("");
}
}