fork download
  1. // EQUALIZE THE STRINGS
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define endl "\n"
  7. #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  8. #define ll long long
  9. #define vi vector<ll>
  10. #define pb push_back
  11. #define F first
  12. #define S second
  13. #define all(v) (v).begin(),(v).end()
  14. #define pii pair<ll,ll>
  15. #define vii vector<pii>
  16. #define calc_fact(n) tgamma(n+1)
  17. #define inf LONG_LONG_MAX
  18. #define MOD 1000000007
  19. #define mod 998244353
  20.  
  21. signed main()
  22. {
  23. FIO;
  24.  
  25. ll n;
  26. string s1,s2,s="";
  27. cin>>n>>s1>>s2;
  28.  
  29. // make a new string
  30. // s[i] = '1' denotes s1[i] == s2[i]
  31. // s[i] = '0' denotes s1[i] != s2[i]
  32.  
  33. for(ll i=0;i<n;i++)
  34. {
  35. if(s1[i]==s2[i])s+="1";
  36. else
  37. s+="0";
  38. }
  39.  
  40. ll ans=0;
  41.  
  42. // increment answer for every consecutive segment of unmatched characters when s[i-1] is '0'
  43.  
  44. for(ll i=1;i<n;i++)
  45. {
  46. if(s[i]!=s[i-1] and s[i-1]=='0')ans++;
  47. }
  48.  
  49. if(s[n-1]=='0')ans++;
  50. cout<<ans<<endl;
  51.  
  52. }
Success #stdin #stdout 0.01s 5280KB
stdin
1 
4
0110
1001
stdout
1