Created
April 23, 2012 16:56
-
-
Save yasith/2472278 to your computer and use it in GitHub Desktop.
TopCoder SRM 541 d2 250
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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