P1200 [USACO1.1] 你的飞碟在这里
知识点——将A-Z输出成1-26 1.理论知识,关于ASCLL码,int 与 bit 之间相差一个数字 0,即48,而1 bit为两个字节,所以int 与 字节 相差 96; 2.用小写英文字符a-z分别减去96,可得相应数字1-26;(其实是每个字符的ascll码相减)
import java.util.Map;
import java.util.Scanner;
public class Main {
/**
* 计算各字符串的乘积
* @param str 被计算的字符串
* @return 乘积
*/
public static int product(String str){
int pro = 1;
byte[] bytes = str.getBytes();
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
int p = b - 96;
pro = pro * p;
}
return pro;
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
//彗星名
String cN = input.next();
String cometName = cN.toLowerCase();
//队伍名
String tN = input.next();
String teamName = tN.toLowerCase();
if (cometName.length() <= 6 && teamName.length() <= 6){
int cometProduct = product(cometName);
int teamProduct = product(teamName);
if (teamProduct % 47 == cometProduct % 47){
System.out.print("GO");
}else {
System.out.print("STAY");
}
}
}
}