import java.util.*;
class App {
public static void main
(String[] args
) {
String a
[] = {"ola",
"lao",
"aol",
"asd",
"asdf",
"fdsa"}; List
<Integer
> lista
= new ArrayList
<Integer
>(Collections.
nCopies(a.
length,
0));
int num=1;
for(int i=0; i<a.length; i++){
if(lista.get(i)==0){
lista.set(i, num);
for(int j=i+1; j<a.length; j++)
if( lista.get(j)==0 && sameChars(a[i], a[j]))
lista.set(j, num);
num++;
}
}
num--;
StringBuilder sb[] = new StringBuilder[num];
for(int i=0; i<num; i++)
sb[i] = new StringBuilder();
for(int i=0; i<lista.size(); i++){
sb[lista.get(i)-1].append(a[i]);
sb[lista.get(i)-1].append(" ");
}
int i=0;
for(StringBuilder s : sb)
str[i++] = s.deleteCharAt(s.length()-1).toString();
imprime(str);
}
static boolean sameChars
( String firstStr ,
String secondStr
) { char[ ] first = firstStr.toCharArray( );
char[ ] second = secondStr.toCharArray( );
return Arrays.
equals( first , second
); }
static void imprime
(String[] sb
) { int num = sb.length;
for(int i=0; i < num; i++){
System.
out.
print("\""+sb
[i
]+"\""); if(i!=num-1)
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgQXBwIHsKCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgogICAgICAgIFN0cmluZyBhW10gPSB7Im9sYSIsImxhbyIsImFvbCIsImFzZCIsImFzZGYiLCJmZHNhIn07ICAgICAgIAogICAgICAgIExpc3Q8SW50ZWdlcj4gbGlzdGEgPSBuZXcgQXJyYXlMaXN0PEludGVnZXI+KENvbGxlY3Rpb25zLm5Db3BpZXMoYS5sZW5ndGgsIDApKTsKCiAgICAgICAgaW50IG51bT0xOwogICAgICAgIGZvcihpbnQgaT0wOyBpPGEubGVuZ3RoOyBpKyspewogICAgICAgICAgICBpZihsaXN0YS5nZXQoaSk9PTApewogICAgICAgICAgICAgICAgbGlzdGEuc2V0KGksIG51bSk7CiAgICAgICAgICAgICAgICBmb3IoaW50IGo9aSsxOyBqPGEubGVuZ3RoOyBqKyspCiAgICAgICAgICAgICAgICAgICAgaWYoIGxpc3RhLmdldChqKT09MCAmJiBzYW1lQ2hhcnMoYVtpXSwgYVtqXSkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxpc3RhLnNldChqLCBudW0pOwogICAgICAgICAgICAgICAgbnVtKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIG51bS0tOwogICAgICAgIFN0cmluZ0J1aWxkZXIgc2JbXSA9IG5ldyBTdHJpbmdCdWlsZGVyW251bV07CiAgICAgICAgZm9yKGludCBpPTA7IGk8bnVtOyBpKyspCiAgICAgICAgICAgIHNiW2ldID0gbmV3IFN0cmluZ0J1aWxkZXIoKTsKCgogICAgICAgIGZvcihpbnQgaT0wOyBpPGxpc3RhLnNpemUoKTsgaSsrKXsKICAgICAgICAgICAgc2JbbGlzdGEuZ2V0KGkpLTFdLmFwcGVuZChhW2ldKTsKICAgICAgICAgICAgc2JbbGlzdGEuZ2V0KGkpLTFdLmFwcGVuZCgiICIpOwogICAgICAgIH0KCiAgICAgICAgU3RyaW5nW10gc3RyID0gbmV3IFN0cmluZ1tzYi5sZW5ndGhdOwogICAgICAgIGludCBpPTA7CiAgICAgICAgZm9yKFN0cmluZ0J1aWxkZXIgcyA6IHNiKQogICAgICAgICAgICBzdHJbaSsrXSA9IHMuZGVsZXRlQ2hhckF0KHMubGVuZ3RoKCktMSkudG9TdHJpbmcoKTsKCiAgICAgICAgaW1wcmltZShzdHIpOwogICAgfQoKCiAgICBzdGF0aWMgYm9vbGVhbiBzYW1lQ2hhcnMoIFN0cmluZyBmaXJzdFN0ciAsIFN0cmluZyBzZWNvbmRTdHIgKSB7CiAgICAgICAgY2hhclsgXSBmaXJzdCAgPSBmaXJzdFN0ci50b0NoYXJBcnJheSggKTsKICAgICAgICBjaGFyWyBdIHNlY29uZCA9IHNlY29uZFN0ci50b0NoYXJBcnJheSggKTsKICAgICAgICBBcnJheXMuc29ydCggZmlyc3QgKTsKICAgICAgICBBcnJheXMuc29ydCggc2Vjb25kICk7CiAgICAgICAgcmV0dXJuIEFycmF5cy5lcXVhbHMoIGZpcnN0ICwgc2Vjb25kICk7CiAgICB9CgogICAgc3RhdGljIHZvaWQgaW1wcmltZShTdHJpbmdbXSBzYikgewogICAgICAgIGludCBudW0gPSBzYi5sZW5ndGg7CiAgICAgICAgU3lzdGVtLm91dC5wcmludCgieyIpOwogICAgICAgIGZvcihpbnQgaT0wOyBpIDwgbnVtOyBpKyspewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCJcIiIrc2JbaV0rIlwiIik7CiAgICAgICAgICAgIGlmKGkhPW51bS0xKQogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludCgiLCAiKTsKICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludCgifSIpOwogICAgfQp9