/* * * 标题:密文搜索
福尔摩斯从X星收到一份资料,全部是小写字母组成。 他的助手提供了另一份资料:许多长度为8的密码列表。 福尔摩斯发现,这些密码是被打乱后隐藏在先前那份资料中的。
请你编写一个程序,从第一份资料中搜索可能隐藏密码的位置。要考虑密码的所有排列可能性。
数据格式:
输入第一行:一个字符串s,全部由小写字母组成,长度小于1024*1024 紧接着一行是一个整数n,表示以下有n行密码,1<=n<=1000 紧接着是n行字符串,都是小写字母组成,长度都为8
要求输出: 一个整数, 表示每行密码的所有排列在s中匹配次数的总和。 */
import java.util.Scanner; public class Test5 { static int count=0; public static void main(String[] args) { // TODO Auto-generated method stub Scanner du=new Scanner(System.in); String str=""; int n=0; str=du.nextLine(); n=du.nextInt(); int shu[][]=new int [n][26]; String mima[]=new String [n]; du.nextLine(); for(int i=0;i<n;i++) { mima[i]=du.nextLine(); } for(int i=0;i<n;i++) { char[] ch=mima[i].toCharArray(); for(int j=0;j<8;j++) { shu[i][ch[j]-'a']++; } } for(int i=0;i<str.length()-7;i++) { char[] temp=str.substring(i, i+8).toCharArray(); int num[]=new int [26]; for(int j=0;j<8;j++) { num[temp[j]-'a']++; } for(int k=0;k<n;k++) { if(check(num,shu[k])) { count++; } } } System.out.println(count); } public static boolean check(int num[],int shu[]) { for(int i=0;i<26;i++) { if(num[i]!=shu[i]) return false; } return true; } }