fork download
  1. /*---------------------------*\
  2. ____________Mari000____________
  3. ________Mostafa Shehab________
  4. \*---------------------------*/
  5.  
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8.  
  9. #define PI 3.14159265
  10. #define EPS (1e-10)
  11. #define endl "\n"
  12. typedef long long ll;
  13. typedef long double ld;
  14.  
  15. ll power(ll x,ll y,ll p);
  16. int Bit(ll x);
  17. ll sum(ll x);
  18.  
  19.  
  20. void Fast(){
  21. std::ios_base::sync_with_stdio(0);
  22. cin.tie(NULL); cout.tie(NULL);
  23. }
  24. inline int D(){
  25. int t;
  26. scanf("%d",&t);
  27. return t;
  28. }
  29. inline ll llD(){
  30. ll t;
  31. scanf("%lld",&t);
  32. return t;
  33. }
  34.  
  35. const int N=55;
  36. char arr[N];
  37. bool visit[N];
  38. int ans[N];
  39. ll t,a,b,k;
  40.  
  41. void seive(){
  42.  
  43. for(int i=2;i<N;++i){
  44. if(visit[i])
  45. continue;
  46. for(int j=i;j<N;j+=i)
  47. ++ans[j],visit[j]=true;
  48. }
  49.  
  50. }
  51.  
  52. int mn=INT_MAX;
  53.  
  54. int main(){
  55. int n=D();
  56. scanf("%s",arr);
  57. string str="ACTG";
  58. for(int i=0;i<n-3;++i){
  59. int count=0;
  60. count+=min(abs(arr[i]-str[0]),abs('Z'-arr[i]+str[0]-'A'+1));
  61. count+=min(abs(arr[i+1]-str[1]),abs('Z'-arr[i+1]+str[1]-'A'+1));
  62. count+=min(abs(arr[i+2]-str[2]),abs('Z'-arr[i+2]+str[2]-'A'+1));
  63. count+=min(abs(arr[i+3]-str[3]),abs('Z'-arr[i+3]+str[3]-'A'+1));
  64. mn=min(count,mn);
  65.  
  66. }
  67. cout<<mn;
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. ll power(ll x,ll y,ll p){
  81. ll res = 1; // Initialize result
  82.  
  83. x = x % p; // Update x if it is more than or
  84. // equal to p
  85. while (y > 0){
  86. // If y is odd, multiply x with result
  87. if (y & 1)
  88. res = (res*x) % p;
  89.  
  90. // y must be even now
  91. y = y>>1; // y = y/2
  92. x = (x*x) % p;
  93. }
  94. return res;
  95. }
  96.  
  97. int Bit(ll x){
  98. if(!x)
  99. return 0;
  100. return 1+Bit(x>>1);
  101. }
  102.  
  103. ll sum(ll x){
  104.  
  105. return x*(x+1)/2;
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
Success #stdin #stdout 0s 15240KB
stdin
4
ACTZ
stdout
7