一个让我爆零的水题,,,,,
codeforces 1151A 1000分
题意:一个字符串,单个字符可以一步可以变成左右两个(Z可以变成Y,A),问最低多少步可以产生“ACTG”;
错因:错误的理解了s[i]-'0'的含义了,0的ASCLL码是48!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1 #include <iostream> 2 #include <cmath> 3 #include <cstdio> 4 #include <cstring> 5 #include <string> 6 #include <map> 7 #include <iomanip> 8 #include <algorithm> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <vector> 13 //const int maxn = 1e5+5; 14 #define ll long long 15 //#define MAX INT_MAX 16 #define FOR(i,a,b) for( int i = a;i <= b;++i) 17 //#define MOD 142857 18 using namespace std; 19 char c; 20 int n,minn=INT_MAX,ans1,ans2,ans3,ans4,sum,a,b,ans; 21 string s; 22 int main() 23 { 24 // freopen("D:\\common_text\\code_stream\\in.txt","r",stdin); 25 // freopen("D:\\common_text\\code_stream\\out.txt","w",stdout); 26 cin>>n>>s; 27 for(int i=0;i<=n-4;++i) 28 { 29 sum=0; 30 int a=abs(s[i]-'A'); 31 int b=abs(s[i+1]-'C'); 32 int c=abs(s[i+2]-'T'); 33 int d=abs(s[i+3]-'G'); 34 sum+=min(a,26-a)+min(b,26-b)+min(c,26-c)+min(d,26-d); 35 if(minn>sum) 36 minn=sum; 37 } 38 cout<<minn; 39 }