Atom
BAN USER-Look at customers if there is a customer who prefers only one dish, take that dish.
-If there is unsatisfied customers
Sort the dishes according to the number of customers who prefer the dish
in decreasing order.
Exclude dishes that has no preferring customers.
While there are still unsatisfied customers
Add dishes one by one to the previously selected dishes,beginning from the top
of the list, check if all customers are satisfied every time, if yes finish.
Then make combinations of two, three, four...., also beginning from the top of the
list, add them and check until all customers are satisfied.
public static String reverseString(String str)
{
char[] arr = str.toCharArray();
char temp;
int i = 0;
int j = str.length() - 1;
while(i < j)
{
while(Character.isWhitespace(arr[i]))
i++;
while(Character.isWhitespace(arr[j]))
j--;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
return new String(arr);
}
While there are still dishes not taken.
- Atom July 29, 2015I'm sorry, but a small correction doesn't hurt