package contcurrentandalgorithm; /** * * @author Administrator * zyyjiao@mail.ustc.edu.cn */ public class SushuStringFind { public static void main(String[] args) { int primeNumber[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101}; String strOne = "ABCDEFGHLMNOPQRS"; String strTwo = "ABCDEFGHL"; // 这里需要用到大整数 int product = 1; //大整数除法的代码,下头给出。 // 遍历长字符串,得到每个字符对应素数的乘积 for (int i = 0; i < strOne.length(); i++) { int index = strOne.charAt(i) - 'A'; product = product * primeNumber[index]; } // 遍历短字符串 for (int j = 0; j < strTwo.length(); j++) { int index = strTwo.charAt(j) - 'A'; // 如果余数不为0,说明不包括短字串中的字符,跳出循环 if (product % primeNumber[index] != 0) { break; } if (strTwo.length() == j) //cout << "true" << endl; { System.out.println("true"); } else //cout << "false" << endl; { System.out.println("false"); } } } } |