Skip to content

Commit

Permalink
hackerrank
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiezhu committed Mar 5, 2015
1 parent 9da8aa7 commit 8ab09fe
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions algorithm-contests.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

45 changes: 45 additions & 0 deletions src/com/jackiezhu/FindHackerRankSolution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.jackiezhu;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by JackieZhu on 15/3/5.
*/
public class FindHackerRankSolution {

public static int findHackerRank(String s) {
String regex = "\\bhackerrank\\b";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s);
boolean isStart = false, isEnd = false;
while(matcher.find()) {
if(matcher.start() == 0) {
isStart = true;
}
if(matcher.start() == s.length() - "hackerrank".length()) {
if(isStart) {
return 0;
} else {
return 2;
}
}
}
if(isStart) {
return 1;
} else {
return -1;
}
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for(int i=0; i<n; i++) {
String s = scanner.nextLine();
System.out.println(findHackerRank(s));
}
}
}
8 changes: 8 additions & 0 deletions src/com/jackiezhu/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.jackiezhu;

public class Main {

public static void main(String[] args) {
// write your code here
}
}

0 comments on commit 8ab09fe

Please sign in to comment.