标签:static span str substr ring system.in 不同 不同的 aaaaa
1 import java.text.DecimalFormat; 2 import java.text.NumberFormat; 3 import java.util.ArrayList; 4 import java.util.Arrays; 5 import java.util.Collection; 6 import java.util.Collections; 7 import java.util.List; 8 import java.util.Scanner; 9 import java.util.Stack; 10 public class Main{ 11 public static void main(String[] args){ 12 Scanner input = new Scanner(System.in); 13 int n = input.nextInt(); 14 String s = input.next(); 15 List<A> list = new ArrayList<A>(); 16 int h = 0; 17 String temp; 18 for(int i=0;i<s.length();i++){ 19 for(int j=i+1;j<=s.length();j++){ 20 if(j-i>=n){ 21 temp = s.substring(i, j); 22 int k; 23 for(k=0;k<list.size();k++){ 24 if(temp.equals(list.get(k).s)){ 25 list.get(k).n++; 26 break; 27 } 28 29 } 30 if(k==h){ 31 A a = new A(); 32 a.s = temp; 33 a.time = h; 34 list.add(a); 35 h++; 36 } 37 } 38 } 39 } 40 Collections.sort(list); 41 System.out.println(list.get(list.size()-1).s); 42 } 43 static class A implements Comparable<A>{ 44 String s; 45 int n; 46 int time; 47 @Override 48 public int compareTo(A a) { 49 // TODO Auto-generated method stub 50 int result; 51 if(n!=a.n){ 52 result = n-a.n; 53 }else if(s.length()!=a.s.length()){ 54 result = s.length()-a.s.length(); 55 }else{ 56 result = a.time-time; 57 } 58 return result; 59 } 60 } 61 }
标签:static span str substr ring system.in 不同 不同的 aaaaa
原文地址:http://www.cnblogs.com/lolybj/p/6528419.html