fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. #define pb push_back
  5. #define mp make_pair
  6.  
  7. ll func(char a, char b, char c, char d){
  8. if(a == b){
  9. if((c != d) && (c != a) && (d != a)){//cout << "ok\n";
  10. return 2;
  11. }
  12.  
  13. else if((c != d) && ((c == a) || (d == a))){
  14. return 1;
  15. }
  16.  
  17. else if(c == a && d == a)
  18. return 0;
  19.  
  20. else if((c == d) && (c != a))
  21. return 0;
  22. }
  23.  
  24. else{
  25. if((c != d) && (c != a) && (c != b) && (d != a) && (d != b))
  26. return 2;
  27.  
  28. else if((c != d) && (((c == a) && (d == b)) || ((c == b) && (d == a))))
  29. return 0;
  30.  
  31. else if((c != d) && ((c == a) || (c == b) || (d == a) || (d == b)))
  32. return 1;
  33.  
  34. else if((c == d) && ((c == a) || (c == b)))
  35. return 1;
  36.  
  37. else if((c == d) && ((c != a) && (c != b)))
  38. return 1;
  39. }
  40. return 0;
  41. }
  42.  
  43. int main() {
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46.  
  47. int n;
  48. cin >> n;
  49. string a, b;
  50. cin >> a >> b;
  51. //cout << func('a', 'a', 'c', 'b') << endl;
  52. ll ans = 0;
  53. for(int i = 0, j = n-1; i <= j; i++, j--){//cout << i << " " << j << endl;
  54. if(i == j){
  55. if(a[i] != b[i])
  56. ans++;
  57. }
  58. else
  59. ans += func(a[i], a[j], b[i], b[j]);
  60. // cout << ans << endl;
  61. }
  62.  
  63. cout << ans;
  64. return 0;
  65. }
Success #stdin #stdout 0s 4196KB
stdin
6
caabbb
bbbaaa
stdout
1