Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Given a document, how to find pairs of words with same charactors but different order.

Go down

Given a document, how to find pairs of words with same charactors but different order. Empty Given a document, how to find pairs of words with same charactors but different order.

Post  Admin Sat Aug 27, 2011 4:05 pm

public static void findpairs(String file){
String[] str=file.split(" ");
for(int i=0;i<str.length();i++){
HashSet<String> hash=new HashSet<String>();
char[] ch=str[i].toCharArray();
for(int z=0;z<ch.length();z++)
hash.put(new Charactor(ch[z]));
for(int j=i+1;j<str.length();j++){
if(str[j].length()!=str[i])
continue;
char[] test=str[j].toCharArray();
boolean flag=true;
for(int p=0;p<test.length();p++){
if(!hash.contains(new Charactor(test[p])))
flag=false;
}
}
if(flag)
System.out.print("The similar pairs are "+str[i]+" and "+str[j]);
}
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum