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

View previous topic View next topic Go down

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

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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