Skip to content

Instantly share code, notes, and snippets.

@yasith
Created April 23, 2012 16:56
Show Gist options
  • Save yasith/2472280 to your computer and use it in GitHub Desktop.
Save yasith/2472280 to your computer and use it in GitHub Desktop.
TopCoder SRM 541 d2 250
import java.util.HashMap;
public class AkariDaisukiDiv2 {
public int countTuples(String S) {
int ans = 0;
HashMap map = new HashMap<String, Integer>();
for(int i = 1; i < S.length(); i++){
for(int j = i+1; j < S.length(); j++){
String ss = S.substring(i, j);
//System.out.println(ss);
if(S.replaceAll("[a-z]+"+ss+"[a-z]+"+ss+"[a-z]+", "").length() == 0){
if(! map.containsKey(ss)){
map.put(ss, 1);
System.out.println(ss);
ans ++;
}
}
}
}
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment