fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.regex.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static final Pattern UNHAPPYG = Pattern.compile("(?<!g)g(?!g)");
  11. private static final boolean gHappy(String str) {
  12. return !UNHAPPYG.matcher(str).find();
  13. }
  14.  
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. String[] inputs = {"xxggxx", "xxgxx", "", "g", "a", "ggaagg", "ggaag"};
  18. for (String input : inputs) {
  19. System.out.printf("Input %s: %s%n", input, gHappy(input));
  20. }
  21. }
  22. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Input xxggxx: true
Input xxgxx: false
Input : true
Input g: false
Input a: true
Input ggaagg: true
Input ggaag: false