Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- int count = 0;
- String[] name = {"b","o","s","c","o"};
- List<String> listDict = new ArrayList<String>();
- listDict.addAll(Arrays.asList(name));
- List<String> newName = new ArrayList<String>();
- Set<String> setOfChars = new HashSet();
- String actualWord = "";
- Boolean subsetWasFound = Boolean.FALSE;
- int countALoops = 0;
- for(char c='a';c<='z';c++){
- setOfChars.add(c+"".trim());
- }
- setOfChars.retainAll(listDict);
- a: for(String ch:name){
- Set<String> helpserSet = new HashSet<String>(setOfChars);
- b: for(String nameCh:setOfChars){
- if(!helpserSet.contains(nameCh)){
- continue b;
- }
- count++;
- if(!ch.equals(nameCh)){
- continue;
- }
- if(listDict.contains(nameCh)){
- newName.add(nameCh);
- listDict.remove(nameCh);
- helpserSet.removeAll(newName);
- }
- }
- if(listDict.isEmpty()){
- break;
- }
- }
- System.out.println(newName);
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement