hdu 2328 暴力枚举+find()

点击打开链接
//暴力+find()
#include <iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int maxr=4000+5;
const int maxc=200+5;
vector<string>str;
char ss[maxr][maxc];
int main()
{
        int n;
        while(scanf("%d",&n)==1&&n)
        {
            for(int i=0;i<n;i++)
                 scanf("%s",&ss[i]);
        string b;
        b.clear();
        b=ss[0];
        //以0串作为模式串进行匹配
        int t=b.length();
        for(int i=0;i<t;i++)       //起始位置
        {
            string k;
            k.clear();
            k=b.substr(i);
             for(int len=1;i+len<=t;len++)                 //左闭右开
            {
                  string f;
                  f.clear();
                  f=k.substr(0,len);
                  //next数组取0-len长度
                  bool flag=true;
                  for(int x=1;x<n;x++)
                  {
                      string f1;
                      f1.clear();
                      f1=ss[x];
                      if(f1.find(f)==string::npos) {
                        flag=false;
                        break;
                      }
                  }
                  if(flag) {
                    if(!str.size()) {
                        str.push_back(f);
                    }
                    else {
                        int m=f.length();
                        if(m<str[0].length()) continue;
                        if(m>str[0].length()) str.clear();
                        str.push_back(f);
                    }
                  }
            }
        }
        if(!str.size()) printf("IDENTITY LOST\n");
        else {
            sort(str.begin(),str.end());
            cout<<str[0]<<endl;
        }
        str.clear();
        }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值