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 CountThat
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13.  
  14. int i,count=0,pos,flag;
  15. char ch;
  16. String s="ABthatCDthatBHthatIOthatoo";
  17.  
  18.  
  19. for(i=0;i<s.length();i++)
  20. {
  21. pos=0;
  22. flag=0;
  23. ch=s.charAt(i);
  24.  
  25. while(true) //while pos<"that".length()
  26. {
  27. if(ch!="that".charAt(pos))
  28. {
  29. flag=1;
  30. break;
  31. }
  32. pos++;
  33. if(pos<4) //"that".length()=4
  34. ch=s.charAt(i+pos);
  35. else
  36. break;
  37. }
  38. if(flag==0)
  39. {
  40. count++;
  41. i+="that".length()-1;
  42. }
  43. }
  44. System.out.println(count);
  45. }
  46. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
4