fork(1) download
  1. /* package whatever; // don't place package name! */
  2. import java.util.regex.Pattern;
  3. import java.util.regex.Matcher;
  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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Pattern pat = Pattern.compile( "^(?!.*__)(?=[A-Za-z])[a-z A-Z0-9_]+(?<![ _])$" );
  13. String text = "c a b d";
  14. for ( int i=0; i<100; i++ ) {
  15. long t1 = System.currentTimeMillis();
  16.  
  17. test(text, pat);
  18.  
  19. long t2 = System.currentTimeMillis();
  20. System.out.println( t2 - t1 ) ;
  21. }
  22. }
  23.  
  24. public static boolean test(String text, Pattern p) {
  25. boolean b = false;
  26. for ( int i=0; i<400000; i++ ) {
  27. b = match(text, p);
  28. }
  29.  
  30. return b;
  31. }
  32.  
  33. public static boolean match(String text, Pattern p) {
  34. Matcher m = p.matcher( text );
  35.  
  36. return m.matches();
  37. }
  38. }
Time limit exceeded #stdin #stdout 5s 320576KB
stdin
Standard input is empty
stdout
3777