Given a document, how to find pairs of words with same charactors but different order.
Page 1 of 1
Given a document, how to find pairs of words with same charactors but different order.
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]);
}
}
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]);
}
}
Similar topics
» Find pairs in an array that sum to y
» Find duplicate words in a string
» Find a point in an array where sum of left side array members(wrt to that point) and right side(wrt to that point) are equal..in other words equilibrium point.
» Given a sorted array find all possible |ai - aj| where ai,aj belongs to Array A. n^2 is obvious. Find a solution in O(N).
» Find if a singly linked List has loop or not. How to find out middle element from a looped single linked list
» Find duplicate words in a string
» Find a point in an array where sum of left side array members(wrt to that point) and right side(wrt to that point) are equal..in other words equilibrium point.
» Given a sorted array find all possible |ai - aj| where ai,aj belongs to Array A. n^2 is obvious. Find a solution in O(N).
» Find if a singly linked List has loop or not. How to find out middle element from a looped single linked list
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|