首页 > 代码库 > Codeforces 96C - Hockey

Codeforces 96C - Hockey

96C - Hockey

字符串处理

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=105;
const int INF=0x7f7f7f7f;
char s[N][N];
char res[N],ss;
int vis[N]={0};
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        getchar();
        cin>>s[i];
    }
    getchar();
    cin>>res;
    getchar();
    cin>>ss;
    for(int j=0;j<n;j++)
    for(int i=0;i<strlen(res);i++)
    {
        if(abs(s[j][0]-res[i])==a-A||abs(s[j][0]-res[i])==0)
        {
            bool flag=true;
            for(int k=0;k<strlen(s[j]);k++)
                if(abs(s[j][k]-res[i+k])!=a-A&&abs(s[j][k]-res[i+k])!=0)flag=false;
            if(flag)
            {
                for(int k=0;k<strlen(s[j]);k++)vis[i+k]=1;
            }
        }
    }
    for(int i=0;i<strlen(res);i++)
    {
        if(vis[i])
        {
            if(isupper(res[i])&&res[i]!=ss-a+A)res[i]=ss-a+A;
            else if(islower(res[i])&&res[i]!=ss)res[i]=ss;
            else if(isupper(res[i]))
            {
                for(int j=0;j<26;j++)
                    if(res[i]!=A+j)
                    {
                        res[i]=A+j;
                        break;
                    }
            }
            else
            {
                for(int j=0;j<26;j++)
                    if(res[i]!=a+j)
                    {
                        res[i]=a+j;
                        break;
                    }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

 

Codeforces 96C - Hockey