fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. class SNCOUP
  6. {
  7. public static void main(String[] args) throws IOException
  8. {
  9. int runs = Integer.parseInt(read.readLine().trim());
  10. while(runs-->0)
  11. {
  12. int size = Integer.parseInt(read.readLine().trim());
  13. String first = read.readLine().trim();
  14. String second = read.readLine().trim();
  15. if(!first.contains("*") || !second.contains("*"))
  16. {
  17. if(!(first.contains("*")||second.contains("*")))
  18. {
  19. System.out.println(0);
  20. continue;
  21. }
  22. if(!first.contains("*"))
  23. {
  24. System.out.println(second.split("\\*",-1).length-1);
  25. continue;
  26. }
  27. if(!second.contains("*"))
  28. {
  29. System.out.println(first.split("\\*",-1).length-1);
  30. continue;
  31. }
  32. }
  33. int total = 1;
  34. boolean top = false;
  35. boolean bottom = false;
  36. for(int i = 0; i<size; i++)
  37. {
  38. if(first.charAt(i)=='*')
  39. {
  40. if(!top)
  41. top = true;
  42. else
  43. {
  44. total++;
  45. bottom = false;
  46. }
  47. }
  48. if(second.charAt(i)=='*')
  49. {
  50. if(!bottom)
  51. bottom = true;
  52. else
  53. {
  54. total++;
  55. top = false;
  56. }
  57. }
  58. }
  59. System.out.println(total);
  60. }
  61. read.close();
  62. }
  63. }
Success #stdin #stdout 0.15s 2841600KB
stdin
3
6
***...
...***
2
..
**
10
*..*..*..*
.*..*..**.
stdout
5
2
4