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代码,很慢,很水import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { int capacity; char[] customers; Map<Character,String> beds; Map<Character,String> left; int count; Scanner sc = new Scanner(System.in); while(true){ capacity = sc.nextInt(); if(capacity==0) return; customers = sc.next().toCharArray(); count=0; beds = new HashMap<Character, String>(); left = new HashMap<Character, String>(); for (int i = 0; i < customers.length; i++) { if(beds.containsKey(customers[i])) beds.remove(customers[i]); else{ if(left.containsKey(customers[i])) left.remove(customers[i]); else if(beds.size()>=capacity){ count++; left.put(customers[i],""); } else{ beds.put(customers[i],""); } } } if(count==0) System.out.println("All customers tanned successfully."); else System.out.println(count + " customer(s) walked away."); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator