Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

java

Posted by a18945028152 at 2019-03-07 20:01:44 on Problem 1200
import 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator