fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t,n,x;
  6. cin >> t;
  7. while(t--){
  8. cin >> n;
  9. string e,g;
  10. cin >> e >> g;
  11. int r = 0;
  12. for(int i=0;i<n;i++){
  13. if(g[i] == '1'){
  14. if(i>0 && i<n-1){
  15. if(e[i-1] == '1')
  16. r++,e[i-1] = 'c';
  17. else if(e[i] == '0')
  18. r++,e[i] = 'c';
  19. else if(e[i+1] == '1')
  20. r++,e[i+1] = 'c';
  21. }else{
  22. if(i == 0){
  23. if(e[i] == '0')
  24. r++,e[i] = 'c';
  25. else if(e[i+1] == '1')
  26. r++,e[i+1] = 'c';
  27. }else{
  28. if(e[i-1] == '1')
  29. r++,e[i-1] = 'c';
  30. else if(e[i] == '0')
  31. r++,e[i] = 'c';
  32. }
  33. }
  34. }
  35. }
  36. cout << r << endl;
  37.  
  38.  
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 5284KB
stdin
2
4
0111
1111
4
0110
1010
stdout
3
2