fork download
  1. /*
  2. " وَكَانَ فَضْلُ اللَّهِ عَلَيْكَ عَظِيمًا "
  3.  
  4. ╔░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╗
  5. ║ ║
  6. ║ ███╗ ███╗ ██████╗ ██╗ ██╗ █████╗ ███╗ ███╗ ███████╗ ██████╗ ║
  7. ║ ████╗ ████║██╔═══██╗██║ ██║ ██╔══██╗ ████╗ ████║ ██╔════╝ ██╔══██╗ ║
  8. ║ ██╔████╔██║██║ ██║███████║ ███████║ ██╔████╔██║ █████╗ ██║ ██║ ║
  9. ║ ██║╚██╔╝██║██║ ██║██╔══██║ ██╔══██║ ██║╚██╔╝██║ ██╔══╝ ██║ ██║ ║
  10. ║ ██║ ╚═╝ ██║╚██████╔╝██║ ██║ ██║ ██║ ██║ ╚═╝ ██║ ███████╗ ██████╔╝ ║
  11. ║ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ║
  12. ║ ║
  13. ║ ██╗ ██╗ ██████╗ ███████╗ ███████╗ █████╗ ███╗ ███╗ ║
  14. ║ ██║ ██║ ██╔═══██╗ ██╔════╝ ██╔════╝ ██╔══██╗ ████╗ ████║ ║
  15. ║ ███████║ ██║ ██║ ███████╗ ███████╗ ███████║ ██╔████╔██║ ║
  16. ║ ██╔══██║ ██║ ██║ ╚════██║ ╚════██║ ██╔══██║ ██║╚██╔╝██║ ║
  17. ║ ██║ ██║ ╚██████╔╝ ███████║ ███████║ ██║ ██║ ██║ ╚═╝ ██║ ║
  18. ║ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ║
  19. ║ ║
  20. ╚░░░░░░░░░░░░░░░░░░░░░░░ MOHAMED HOSSAM | SOFTWARE ENGINEER ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╝
  21. */
  22.  
  23. #include"bits/stdc++.h"
  24. using namespace std;
  25. #define el '\n'
  26. #define ll long long
  27. #define int long long
  28. #define yes cout << "YES\n"
  29. #define no cout << "NO\n"
  30. #define all(x) (x).begin(), (x).end()
  31. #define rall(x) x.rbegin(), x.rend()
  32. #define sz(x) ((int)(x).size())
  33.  
  34. template<class T, class U>
  35. T GCD(T a, U b) { return (!b ? a : GCD(b, a % b)); }
  36. template<class T, class U>
  37. T LCM(T a, U b) { return ((a / GCD(a, b)) * b); }
  38.  
  39. constexpr ll MAX = 300000, MOD = 998244353, MAXN = 2e5 + 10, inf = 1e18;
  40. using vi = vector<int>;
  41. int dx[] = {-1, 1, 0, 0};
  42. int dy[] = {0, 0, -1, 1};
  43. void free_palestine() {
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46. cout.tie(NULL);
  47.  
  48. #ifndef ONLINE_JUDGE
  49. freopen("inputs.txt", "r", stdin);
  50. freopen("output.txt", "w", stdout);
  51. #endif
  52. }
  53.  
  54. template<typename T>
  55. istream &operator>>(istream &in, vector<T> &v) {for (auto &x: v) in >> x;return in;}
  56.  
  57. template<typename T>
  58. ostream &operator<<(ostream &out, const vector<T> &v) {for (const auto &x: v) out << x << ' ';return out;}
  59.  
  60. void solve(int tc) {
  61. int n;cin>>n;
  62.  
  63. string s;cin>>s;
  64.  
  65. bool need[26] = {};
  66.  
  67. for (int i=0;i<n/2;i++) {
  68. char a = min(s[i], s[n - 1 - i]),
  69. b = max(s[i], s[n - 1 - i]);
  70.  
  71. for (char c =a+1;c<=b;c++) {
  72. need[c - 'a'] = true;
  73. }
  74. }
  75.  
  76. int ans=0;
  77.  
  78. for (int i = 0; i < 26; i++) {
  79. ans += need[i];
  80. }
  81.  
  82. cout<<ans<<el;
  83.  
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90. int32_t main() {
  91. free_palestine();
  92. // freopen("collectingofficer.in", "r", stdin);// freopen("palindrome.out", "w", stdout);
  93. int tc = 1;
  94.  
  95. cin>>tc;
  96. for (int i = 1; i <= tc; ++i) {
  97. solve(i);
  98. }
  99.  
  100. }
  101.  
Success #stdin #stdout 0s 5344KB
stdin
Standard input is empty
stdout
0