-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem54.java
76 lines (60 loc) · 1.66 KB
/
Problem54.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
72
73
74
75
76
package dimikOJ;
import java.util.Scanner;
public class Problem54 {
public static boolean validtaeString(String str) {
str = str.toLowerCase();
char[] charArray = str.toCharArray();
for (int i = 0; i < charArray.length; i++) {
char ch = charArray[i];
if (!(ch >= 'a' && ch <= 'z')) {
return false;
}
}
return true;
}
public static String checkCollision(String strOne, String strTwo) {
int keyOne = 1, keyTwo = 1;
for (int i = 0; i < strOne.length(); i++) {
int ascii = strOne.charAt(i);
keyOne = keyOne * ascii;
}
for (int i = 0; i < strTwo.length(); i++) {
int ascii = strTwo.charAt(i);
keyTwo = keyTwo * ascii;
}
keyOne = keyOne % 97;
keyTwo = keyTwo % 97;
if (keyOne == keyTwo) {
return "YES";
} else {
return "NO";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
String strOne, strTwo;
int strOneLength, strTwoLength;
int T = input.nextInt();
while (T < 1) {
T = input.nextInt();
}
input.nextLine();
for (int i = 0; i < T; i++) {
strOne = input.next();
strOneLength = strOne.length();
while (strOneLength < 1 || strOneLength > 20 || validtaeString(strOne) == false) {
strOne = input.next();
strOneLength = strOne.length();
}
strTwo = input.next();
strTwoLength = strTwo.length();
while (strTwoLength < 1 || strTwoLength > 20 || validtaeString(strTwo) == false) {
strTwo = input.next();
strTwoLength = strTwo.length();
}
System.out.printf("%s\n", checkCollision(strOne, strTwo));
}
input.close();
}
}