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 |
submit again and again ^_^In Reply To:once ac (java code) Posted by:fishing_test at 2009-05-12 21:40:42 > import java.io.BufferedReader; > import java.io.InputStreamReader; > import java.util.HashSet; > import java.util.Set; > > public class Main { > > private static int[] count = new int[27]; > > private static int current = 0; > > private static int getCount() { > int ret = 0; > > for (int i = 1; i <= 26; i++) { > if (count[i] > 0) { > ret++; > } > } > > return ret; > } > > /** > * @param args > */ > public static void main(String[] args) throws Exception { > BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); > > String line = stdin.readLine(); > > String[] t = line.split("[ ]+"); > > int n = Integer.parseInt(t[0]); > > int nc = Integer.parseInt(t[1]); > > line = stdin.readLine(); > > int len = line.length(); > > Set<String> set = new HashSet<String>(); > > for (int i = 1; i <= 26; i++) { > count[i] = 0; > } > > StringBuilder sb = new StringBuilder(); > > for (int i = 0; i < n; i++) { > sb.append(line.charAt(i)); > count[line.charAt(i) - 'a' + 1]++; > } > > current = getCount(); > > if (current <= nc) { > set.add(sb.toString()); > } > > for (int i = n; i < len; i++) { > char c = sb.charAt(0); > sb.deleteCharAt(0); > > sb.append(line.charAt(i)); > > if (count[c - 'a' + 1] == 1) { > current--; > > count[c - 'a' + 1]--; > } else { > count[c - 'a' + 1]--; > } > > if (count[line.charAt(i) - 'a' + 1] == 0) { > current++; > count[line.charAt(i) - 'a' + 1]++; > } else { > count[line.charAt(i) - 'a' + 1]++; > } > > set.add(sb.toString()); > } > > > > System.out.println(set.size()); > > } > > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator