fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6. public static void main(String[] args) throws IOException{
  7. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  8. String q = bufferedReader.readLine();
  9. int k = Integer.parseInt(q);
  10. String s = bufferedReader.readLine();
  11. int l, r, flag=0, ans=0;
  12. for(int i=0; i<s.length()-k+1; i++)
  13. {
  14. flag=0;
  15. l=i;
  16. r=i+k-1;
  17. for(int j=0; j<k/2; j++)
  18. {
  19. if(s.charAt(l+j)!=s.charAt(r-j)){
  20. flag=1;
  21. break;
  22. }
  23. }
  24. if(flag==0){
  25. ans++;
  26. }
  27. }
  28. System.out.print(ans);
  29. }
  30. }
Success #stdin #stdout 0.04s 2184192KB
stdin
3
babcbab
stdout
3