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 |
用Java的HashMap太给力了。。没用NC就AC了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator