FZU 1937(字符串模拟)

FZU 1937
题目链接
题目大意:给你两个字符串s1,s2要求把s2插入s1(也就是有strlen(s1)+1种新的字符串)看这些中那些是回文的。
思路:给的两个字符串都是小于50个,所以直接模拟。
代码

#include<iostream>
#include<cstdlib> 
#include<sstream>
#include<cstdio>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=1111122;
const int M=200005;
char a[200][200],s[100],s1[100];
int main()
{
    int t,i,j,n,m,w,sum,flag,cnm=0,l1,l2,k;
    cin>>t;
    getchar();
    while(t--)
    {
        sum=0;
        
        gets(s);
        gets(s1);
        l1=strlen(s);
        l2=strlen(s1);
        for(i=0;i<=strlen(s);i++)
        {
            w=0;
            for(j=0;j<strlen(s)+strlen(s1);j++)
            {
                if(j==i)
                {
                    w=1;
                    for(k=0;k<strlen(s1);k++)
                    {
                        a[i][j+k]=s1[k];
                    }
                    j=j+k-1;
                }
                else
                {
                    if(w==0)a[i][j]=s[j];
                    else a[i][j]=s[j-l2];
                } 
            }
        }
        for(i=0;i<=strlen(s);i++)
        {
            flag=0;
            for(j=0;j<(l1+l2)/2;j++)
            {
                if(a[i][j]!=a[i][l1+l2-j-1])flag=1;
            }
            if(flag==0)sum++;
        }
        printf("Case %d: %d\n",++cnm,sum);
    }
   system("pause");
        return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值