fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  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. System.out.println(Ideone.lcs("This entity works ok","This entity works aswell"));
  13. }
  14. public static String lcs(String a, String b){
  15. int aLen = a.length();
  16. int bLen = b.length();
  17. if(aLen == 0 || bLen == 0){
  18. return "";
  19. }else if(a.charAt(aLen-1) == b.charAt(bLen-1)){
  20. return lcs(a.substring(0,aLen-1),b.substring(0,bLen-1))
  21. + a.charAt(aLen-1);
  22. }else{
  23. String x = lcs(a, b.substring(0,bLen-1));
  24. String y = lcs(a.substring(0,aLen-1), b);
  25. return (x.length() > y.length()) ? x : y;
  26. }
  27. }
  28. }
Time limit exceeded #stdin #stdout 5s 320320KB
stdin
Standard input is empty
stdout
Standard output is empty