首页 > 代码库 > 字符串处理

字符串处理

#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<queue>#include<vector>#include<cstring>#include<cmath>#include<map>using namespace std;typedef long long ll;#define N 2011111char str[1111];int s[1111],f[1111][4],d[1111],b[1111];int main(){    int t,k;    cin>>t;    while(t--){        cin>>str>>k;        int len=strlen(str);        for(int i=0;i<len;i++){            if(str[i]==A)s[i]=0;            if(str[i]==T)s[i]=1;            if(str[i]==C)s[i]=2;            if(str[i]==G)s[i]=3;            d[i]=i;        }        int x=len-k;        memset(f,0,sizeof(f));        memset(b,0,sizeof(b));        for(int i=0;i<k;i++){            d[i]=min(d[i],d[x+i]);            d[i+x]=d[i];            if(!b[i])f[d[i]][s[i]]++;b[i]=1;            if(!b[i+x])f[d[i]][s[i+x]]++;b[i+x]=1;        }        int ans=0;        for(int i=0;i<k;i++){            x=0;            int y=0;            for(int j=0;j<4;j++){x+=f[i][j];y=max(y,f[i][j]);}            ans+=x-y;        }        cout<<ans<<endl;    }    return 0;}

 

字符串处理