首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java实现字符串的婚配

2013-12-02 
Java实现字符串的匹配package contcurrentandalgorithm/**** @author Administrator* zyyjiao@mail.ustc.

Java实现字符串的匹配
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"); } } }}? 5 楼 jonas.wang 前天   这个本身只是判断字符串1 是否包含 字符串2 的字符。
且判断的if条件还需要改进下。

热点排行