// Topcoder SRM 584 DIV 2 L1 TopFox
import java.util.*;
//rename the class name before submitting
public class TopFox {
public static void main(String[] args) {
TopFox obj = new TopFox();
System.out.println(obj.possibleHandles(
"ab",
"cd"
));
}
public int possibleHandles(String familyName, String givenName) {
HashSet<String> names = new HashSet<String>();
for (int i = 1; i <= familyName.length(); i++) {
String s1 = familyName.substring(0, i);
for (int j = 1; j <= givenName.length(); j++) {
String s2 = givenName.substring(0, j);
String s = s1 + s2;
names.add(s);
}
}
return names.size();
}
}
No comments:
Post a Comment