fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Codechef
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. // your code goes here
  11. Scanner sc=new Scanner(System.in);
  12. int t=sc.nextInt();
  13.  
  14. for(int i=0;i<t;i++)
  15. {
  16. int d=sc.nextInt();
  17. String s=sc.next();
  18. int count_p=0;
  19. int mincount=0;
  20. for(int j=0;j<s.length();j++)
  21. {
  22. if(s.charAt(j)=='P')
  23. {
  24. count_p++;
  25. }
  26. }
  27. if((count_p/(d*1.0))>=0.75)
  28. {
  29. System.out.println("0");
  30. }
  31. else{
  32. for(int k=2;k<s.length()-2;k++)
  33. {
  34. if(s.charAt(k)=='A')
  35. {
  36. if(s.charAt(k-1)=='P'||s.charAt(k-2)=='P'||
  37. s.charAt(k+1)=='P'||s.charAt(k+2)=='P')
  38. {
  39. count_p++;
  40. mincount++;
  41. if((count_p/(d*1.0))>=0.75)
  42. {
  43. System.out.println(mincount);
  44. break;
  45. }
  46. }
  47. }
  48. }
  49.  
  50. }
  51. }
  52. }
  53. }
  54.  
Runtime error #stdin #stdout #stderr 0.08s 2184192KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Codechef.main(Main.java:12)