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的HashMap太给力了。。没用NC就AC了

Posted by SQK at 2011-03-24 14:10:25 on Problem 1200
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		sc.nextLine();
		String s=sc.nextLine();
		HashMap<String,Integer> hm=new HashMap<String,Integer>();
		String key;
		int k=0;
		for(int i=0;i<s.length()-n+1;i++){
			key=s.substring(i, i+n);
			if(!hm.containsKey(key)){
				hm.put(key, k++);
			}
		}
		System.out.println(hm.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