Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
javaimport java.util.HashSet; import java.util.Scanner; public class poj1200 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { int n=sc.nextInt(); int nc=sc.nextInt(); int max=(int)Math.pow(nc,n); HashSet<String> hash=new HashSet<String>();//实现Set接口 仅存储对象 调用add()方法向Set中添加元素 String s=sc.next(); int m=s.length()-n+1; for(int i=0;i<m;i++) { hash.add(s.substring(i,i+n));//substring是将字符从i截取到i+n if(hash.size()==max) {//size()方法是针对泛型集合说的,size()表示泛型有多少个元素 break;} } System.out.println(hash.size()); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator