fork download
  1. #include <bits/stdc++.h>
  2. #define yo_con_marcelita
  3. #define F first
  4. #define S second
  5. #define pb push_back
  6. #define eb emplace_back
  7. #define ln cout<<endl;
  8. #define sz(x) int((x).size())
  9. #define all(x) (x).begin(), (x).end()
  10. #define rall(x) (x).rbegin(), (x).rend()
  11. #define read(x) for(auto &el : x) cin >> el;
  12. #define For(i,s,n) for(int i=s; i < int(n); ++i)
  13. #define dFor(i,f,n) for (int i = n - 1; i >= f; --i)
  14. #define DBG(x) cout << #x << " = " << x << endl;
  15. #define print(x) for(auto &el : x) {cout << el << " ";} cout<<endl;
  16. #define lw(c, x) int(lower_bound((c).begin(), (c).end(), (x)) - (c).begin())
  17. #define up(c, x) int(upper_bound((c).begin(), (c).end(), (x)) - (c).begin())
  18. #define sino(b) cout<<(b ? "YES\n":"NO\n");
  19. #define syso(x) cout<< (x) <<endl;
  20. #define kill(x) {cout<< (x) <<endl; return;}
  21. using namespace std;
  22. typedef long long ll;
  23. typedef long double ld;
  24. typedef vector<int> vi;
  25. typedef vector<ll> vll;
  26. typedef pair<int,int> pii;
  27. typedef pair<ll,ll> pll;
  28. ll gcd(ll a, ll b){while(b){a%=b; swap(a,b);} return a;} ll lcm(ll a,ll b){return a*b/gcd(a,b);}
  29. int lg2(const int &x) { return 31-__builtin_clz(x);} // int lg2(const ll &x) {return 63-__builtin_clzll(x);}
  30. // Para leer e imprimir .txt
  31. // freopen("input.txt", "r", stdin);
  32. // freopen("output.txt", "w", stdout);
  33.  
  34. void solve() {
  35. int n;
  36. string s;
  37. cin >> n >> s;
  38. vector<bool> need(26,false);
  39. for (int i = 0; i < n / 2; i++) {
  40. int a = s[i] - 'a', b = s[n - 1 - i] - 'a';
  41. if (a > b) swap(a, b);
  42. for (int j = a + 1; j <= b; j++) need[j] = 1;
  43. }
  44.  
  45. int ans = 0;
  46. for (int i = 1; i < 26; i++) {
  47. ans += need[i];
  48. }
  49.  
  50. cout << ans << '\n';
  51. }
  52.  
  53. int main(){
  54. yo_con_marcelita
  55. int t = 1;
  56. cin >> t;
  57. while (t--) {
  58. solve();
  59. }
  60. return 0;
  61. }
  62. //VisualSaquenASebastianDelEquipoPorFavorCode
Success #stdin #stdout 0.01s 5344KB
stdin
5
4
abca
4
abdc
7
racecar
4
cbad
4
zaza
stdout
1
3
0
2
25