题目链接:https://www.luogu.com.cn/problem/P1200
代码实例:
方法一:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String hx = scanner.next();
String xz = scanner.next();
char a[] = new char[]
{'A','B','C','D','E','F','G',
'H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U',
'V','W','X','Y','Z'};
int b = 1,c = 1 ;
for (int i = 0; i < hx.length(); i++) {
for (int j = 0; j < a.length; j++) {
if(hx.charAt(i)==a[j]) {
b *= j+1;
}
}
}
for (int i = 0; i < xz.length(); i++) {
for (int j = 0; j < a.length; j++) {
if(xz.charAt(i)==a[j]) {
c *= j+1;
}
}
}
if(b%47==c%47) {
System.out.println("GO");
}else {
System.out.println("STAY");
}
scanner.close();
}
}
方法二:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String hx = scanner.next();
String xz = scanner.next();
int b = 1,c = 1 ;
for (int i = 0; i < hx.length(); i++) {
b *= (hx.charAt(i)-'@');//这里对应ACSLL码表------->'@'的ACSLL码为64.'A'的ACSLL码为65,所以65-64==1
}
for (int i = 0; i < xz.length(); i++) {
b *= (xz.charAt(i)-'@');
}
if(b%47==c%47) {
System.out.println("GO");
}else {
System.out.println("STAY");
}
scanner.close();
}
}