Advertisement
Guest User

491D-1

a guest
Jun 23rd, 2018
2,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string s[2];
  7.  
  8.     int n = 2;
  9.     int m;
  10.     for (int i = 0; i < n; i++) {
  11.         cin >> s[i];
  12.         m = s[i].length();
  13.     }
  14.  
  15.     int ans = 0;
  16.     int previous = 0;
  17.     for (int i = 0; i < m; i++) {
  18.         int current = (s[0][i] == '0') + (s[1][i] == '0');
  19.  
  20.         if (current == 0)
  21.             previous = 0;
  22.  
  23.         if (current == 1) {
  24.             if (previous == 2) {
  25.                 ans++;
  26.                 previous = 0;
  27.             }
  28.             else
  29.                 previous = 1;
  30.         }
  31.  
  32.         if (current == 2) {
  33.             if (previous > 0) {
  34.                 ans++;
  35.                 if (previous == 2)
  36.                     previous = 1;
  37.                 else
  38.                     previous = 0;
  39.             }
  40.             else
  41.                 previous = 2;
  42.         }
  43.     }
  44.  
  45.     cout << ans;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement