日期:2014-05-20 浏览次数:20814 次
import java.util.*;
public class Move
{
public Move()
{
user = new HashMap<String, Integer>();
}
public void addUser(String userName)
{
user.put(userName, 0);
}
public void addCharge(String userName, int charge)
{
int oldCharge = user.get(userName);
if(0 != oldCharge)
user.put(userName, oldCharge + charge);
user.put(userName, charge);
}
public int balance(String userName)
{
return user.get(userName);
}
//return max and min
public Map<String, Integer> find(int[] arr)
{
Map<List<String>, Integer> result = new HashMap<List<String>, Integer>();
int max = arr[1];
int min = arr[0];
List<String> maxUser = new ArrayList<String>();
List<String> minUser = new ArrayList<String>();
for(Map.Entry<String, Integer> entry : user.entrySet())
{
if(max == entry.getValue)
maxUser.add(entry.getKey());
if(min == entry.getValue)
minUser.add(entry.getKey());
}
temp.put(minUser, min);
temp.put(maxUser, max);
return result;
}
//0 is min, 1 is max
private int[] findMaxOrMin()
{
int[] result = new int[2];
int[] sum = user.values().toArray();
sum.sort();
result[0] = sum[0];
result[1] = sum[sum.length - 1];
return result;
}
private Map<String, Integer> user;
}