fork download
  1.  
  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. Scanner sc=new Scanner(System.in);
  13. String str=sc.next();
  14. String s=sc.next();
  15. char txt[]=str.toCharArray();
  16. char pat[]=s.toCharArray();
  17. int n=txt.length;
  18. int j=0,i=0;
  19. int t=pat.length;
  20. if(n==t){
  21. if(txt[0]!=pat[0])
  22. System.out.println("not a substring");
  23.  
  24. }
  25. if(n>=t){
  26. for( i=0;i<=n-t;i++){
  27. if(pat[j]==txt[i]){
  28. j=0;
  29. for(int k=i;k<t+i;k++){
  30. if(txt[k]!=pat[j])
  31. break;
  32. else
  33. j++;
  34. }
  35. if(j==t)
  36. {
  37. System.out.println(i);
  38. break;
  39. }
  40.  
  41. }
  42. }
  43. if(j!=t){
  44. System.out.println("not found");
  45. }
  46.  
  47. }
  48.  
  49. }
  50.  
  51.  
  52. }
Success #stdin #stdout 0.06s 4386816KB
stdin
sweety
vickyi
stdout
not a substring
not found