import java.util.*;
class CharBag implements Comparable<CharBag> {
public static int CHAR_POWER = 256;
private int[] map = new int[CHAR_POWER];
private int count = 0;
private CharBag copy;
CharBag() {}
this.word = word;
for (int i = 0; i < word.length(); i++) {
this.add(word.charAt(i));
}
copy = new CharBag();
copy.word = word;
}
return word;
}
public int getCount() {
return count;
}
public void add(char c) {
map[(int) c]++;
count++;
}
public boolean remove(char c) {
int index = (int) c;
if (map[index] > 0) {
map[index]--;
count--;
return true;
} else {
return false;
}
}
public boolean checkAnagramDestructive
(String anagram
) { for (int i = 0; i < anagram.length(); i++) {
char c = anagram.charAt(i);
if (!this.remove(c)) {
return false;
}
}
return this.count == 0;
}
private void makeCopy() {
copy.count = count;
System.
arraycopy(map,
0, copy.
map,
0, CHAR_POWER
); }
public boolean checkAnagram
(String anagram
) { makeCopy();
return copy.checkAnagramDestructive(anagram);
}
@Override
public int compareTo(CharBag o) {
return Integer.
compare(this.
count, o.
count); }
}
public class Main {
public static void main
(String[] args
) { Scanner scanner
= new Scanner
(System.
in); String str1
= scanner.
nextLine(); String[] words
= str1.
split("\\s+"); List<CharBag> bags = new ArrayList<>();
bags.add(new CharBag(word));
}
String str2
= scanner.
nextLine(); List<CharBag> matchingBags = new ArrayList<>(words.length);
List<String> anagrams = new ArrayList<>(words.length);
List<String> resultWords = new ArrayList<>(words.length);
while (!(str2.isEmpty() || bags.isEmpty())) {
for (CharBag bag : bags) {
if (bag.checkAnagram(str2.substring(0, bag.getCount()))) {
matchingBags.add(bag);
}
}
if (matchingBags.isEmpty()) {
System.
out.
println("Does not compute."); return;
}
CharBag bagWithMaxLength
= Collections.
max(matchingBags
); int split = bagWithMaxLength.getCount();
anagrams.add(str2.substring(0, split));
resultWords.add(bagWithMaxLength.getWord());
str2 = str2.substring(split);
bags.remove(bagWithMaxLength);
matchingBags.clear();
}
if (!str2.isEmpty()) {
System.
out.
println("Too few words!"); } else if (!bags.isEmpty()) {
System.
out.
println("Too many words!"); } else {
}
for (String w
: resultWords
) { }
}
}
}