fork download
  1.  
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <iostream>
  6. #include <algorithm>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. int main(){
  12.  
  13. int t;
  14. cin>>t;
  15. for(int r=0;r<t;r++){
  16. int q;
  17. cin>>q;
  18. char s[2][q];
  19. char d;
  20. for(int i=0;i<2;i++){
  21. for(int j=0;j<q;j++)
  22. cin>>s[i][j];
  23. }
  24. int c=0;
  25. for(int i=0;i<2;i++){
  26. for(int j=0;j<q;j++)
  27. if(s[i][j]=='*')c++;
  28. }
  29.  
  30. int count=0;
  31. int s1=0;
  32. int s2=0;
  33. d='a';
  34. for(int k=0;k<q;k++){
  35. if(s[0][k]=='*' || s[1][k]=='*') count++;
  36. if(s[0][k]=='*') s2=1;
  37. if(s[1][k]=='*') s1=1;
  38. if(s[0][k]=='*' && s[1][k]=='*') d='c';
  39. }
  40. int hor=s1+s2;
  41.  
  42. if(d=='c'){
  43. if(count-1 == 1 && hor==2 && c>2){cout<<2<<endl; }
  44. if(count-1 == 0 && hor==2 && c==2){cout<<1<<endl; }
  45. if(count-1 == 1 && hor==2 && c==2){cout<<1<<endl; }
  46. if(count-1 > 1 && hor==2 ){cout<<count+hor-2<<endl; }
  47. if(count-1 >= 1 && hor!=2 ){cout<<count-1<<endl; }
  48. if(count-1 ==0 && hor!=2 ){cout<<0<<endl; }
  49. if(count-1 ==0 && hor!=2 && c==2){cout<<1<<endl; }
  50.  
  51. }
  52.  
  53. else if(d!=c){
  54. if(count>=1)cout<<count-1<<endl;
  55. else cout<<0<<endl;}
  56.  
  57.  
  58. }
  59. return 0;
  60.  
  61. }
  62.  
Success #stdin #stdout 0s 15232KB
stdin
1
5
*..*.
.**.*
stdout
4