fork download
  1. /*input
  2. 5
  3. 2
  4. **
  5. **
  6. 3
  7. ***
  8. *..
  9. 3
  10. *..
  11. .*.
  12. 12
  13. .**.*..*****
  14. .**..***.*.*
  15. 6
  16. *.*.*.
  17. .*.*.*
  18. */
  19. #include<bits/stdc++.h>
  20.  
  21. using namespace std;
  22.  
  23. int test, n, board[5][100005], check[5];
  24.  
  25. void Init(){
  26. cin >> n;
  27. // a = b = 0;
  28. check[1] = check[2] = 0;
  29. for(int i = 1; i <= 2; i++){
  30. for(int j = 1; j <= n; j++){
  31. char cak;
  32. cin >> cak;
  33. if(cak == '*') board[i][j] = 1, check[i] = 1;
  34. else board[i][j] = 0;
  35. }
  36. }
  37. return;
  38. }
  39.  
  40. void Solve(){
  41. int res = 0;
  42. if(check[1] && check[2]) res++;
  43. check[1] = check[2] = 0;
  44. for(int i = 1; i <= n; i++){
  45. if(check[1] && board[1][i]){
  46. check[2] = board[2][i];
  47. res++;
  48. }
  49. else if(check[2] && board[2][i]){
  50. check[1] = board[1][i];
  51. res++;
  52. }
  53. else{
  54. check[1] = max(check[1],board[1][i]); check[2] = max(check[2], board[2][i]);
  55. }
  56. }
  57. cout << res << '\n';
  58. }
  59.  
  60. signed main(){
  61. ios_base::sync_with_stdio(0);
  62. cin >> test;
  63. while(test--){
  64. Init();
  65. Solve();
  66. }
  67. }
Success #stdin #stdout 0s 18016KB
stdin
1
10
*.*.*.*.*.
.*.*.*.*.*
stdout
5