当前位置: 首页 > wzjs >正文

商城网站设计策划企业创新平台建设

商城网站设计策划,企业创新平台建设,仿站网站建设,鲜花网站怎么做题目描述 求采用顺序结构存储的串s和串t的一个最长公共子串,若没有则输出false,若最长的有多个则输出最先出现的那一串。 输入 输入两个字符串 输出 输出公共子串 样例输入 abcdef adbcef 样例输出 bc 分析:用字符串哈希解决。检查…
题目描述

求采用顺序结构存储的串s和串t的一个最长公共子串,若没有则输出false,若最长的有多个则输出最先出现的那一串。

输入

输入两个字符串

输出

输出公共子串

样例输入
abcdef
adbcef
样例输出
bc

分析:用字符串哈希解决。检查子串的哈希值是否相等,如果相等,说明是公共子串。书上的模板代码只能求出最长长度,添加一个下标位置即可。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0x3fffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;typedef struct node
{int hashvalue,index;
}node;const long long mod=1e9+7;
const long long p=1e7+19;
const long long maxn=1010;
long long powp[maxn],h1[maxn],h2[maxn];
//vector<pair<int,int>>pr1,pr2;
vector<pair<node,int>>pr1,pr2;void init(int len)
{powp[0]=1;for(int i=1;i<=len;++i)powp[i]=powp[i-1]*p%mod;
}void calh(long long h[],string &str)
{h[0]=str[0];for(int i=1;i<str.length();++i)h[i]=(h[i-1]*p+str[i])%mod;
}int calsinglesubh(long long h[],int i,int j)
{if(i==0)return h[j];return ((h[j]-h[i-1]*powp[j-i+1])%mod+mod)%mod;
}void calsubh(long long h[],int len,vector<pair<node,int>>&pr)
{for(int i=0;i<len;++i){for(int j=0;j<len;++j){int hashvalue=calsinglesubh(h,i,j);
//            pr.push_back(make_pair(hashvalue,j-i+1));node temp;temp.hashvalue=hashvalue,temp.index=i;pr.push_back(make_pair(temp,j-i+1));}}
}int getmax()
{
//    int ans=0;int ans=0,index=-1;for(int i=0;i<pr1.size();++i){for(int j=0;j<pr2.size();++j){
//            if(pr1[i].first==pr2[j].first)
//                ans=max(ans,pr1[i].second);if(pr1[i].first.hashvalue==pr2[j].first.hashvalue){if(ans<pr1[i].second)ans=pr1[i].second,index=i;}}}
//    return ans;return index;
}int main(void)
{#ifdef testfreopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);clock_t start=clock();#endif //teststring str1,str2;getline(cin,str1);getline(cin,str2);init(max(str1.length(),str2.length()));calh(h1,str1);calh(h2,str2);calsubh(h1,str1.length(),pr1);calsubh(h2,str2.length(),pr2);
//    printf("ans=%d\n",getmax());int ind=getmax();if(ind==-1)printf("false\n");else{int index=pr1[ind].first.index,len=pr1[ind].second;for(int i=index,j=0;j<len;++i,++j)printf("%c",str1[i]);}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}


文章转载自:

http://zU6bmkzA.jpydf.cn
http://tBS5x7JY.jpydf.cn
http://1ejkSFs1.jpydf.cn
http://VAStmwso.jpydf.cn
http://SlGpzLuJ.jpydf.cn
http://p8aH2OLK.jpydf.cn
http://myjC4gJ0.jpydf.cn
http://lBGcLb70.jpydf.cn
http://kra3ZrpL.jpydf.cn
http://U9PBBoFp.jpydf.cn
http://Yogax2uC.jpydf.cn
http://WSmXHo21.jpydf.cn
http://geDJAvqM.jpydf.cn
http://saqU0rBf.jpydf.cn
http://8LmnJQOY.jpydf.cn
http://bWvjP3lP.jpydf.cn
http://kxg8LG8Q.jpydf.cn
http://lHz0fi3U.jpydf.cn
http://4cO19i6F.jpydf.cn
http://H7C32Ao9.jpydf.cn
http://9tcB4EZn.jpydf.cn
http://rxdHPwRG.jpydf.cn
http://CIxwVvRA.jpydf.cn
http://1YtTpIwZ.jpydf.cn
http://OkZ6T5S4.jpydf.cn
http://T2tTsiu0.jpydf.cn
http://ya3HlywC.jpydf.cn
http://SxAawAAq.jpydf.cn
http://SIXKOKYf.jpydf.cn
http://j1vhcoRy.jpydf.cn
http://www.dtcms.com/wzjs/683317.html

相关文章:

  • 做原型网站秦皇岛咔咔科技有限公司
  • 需要做网站建设的行业有哪些单页建站系统
  • 做暧昧视频网站怎样找家做网站的公司
  • 做资源的教育类网站或公司沈阳京科医院男科
  • 湖南岳阳网站建设公司黄页顺企网如何做产品网站
  • 湖北建设网站首页wordpress yasaer
  • 帝国cms如何做网站学习软件开发的网站
  • 什么网站有做册子版附近广告公司喷绘刻字
  • 免费域名模板建站分割页面
  • 网站建设实验目的南昌企业建站程序
  • 网站设计的图片邯郸网站建设咨询安联网络
  • 巴彦淖尔网站制作中国职业培训在线官方网站
  • 深圳都信建设监理有限公司网站濮阳 网站建设
  • 响应式网站开发费用如何用python开发网页
  • 做淘客网站注意事项如何做旅游休闲网站
  • 苏州高新区建设局网站外贸网站如何做
  • 网站上的图用美图秀秀做可以吗织梦教育网站模板
  • 花生壳怎么发布自己做的网站2020十大热点事件
  • 网站开发 简单备案网站建设承诺书
  • 网站建设价格报价wordpress采集淘宝
  • 阿里云可以放几个网站建网站的流程和费用
  • 如今流行的网站建设软件界面设计方案
  • 网站前台代码综合性门户网站是什么意思
  • 泰州网站设计培训网站设计建设定制
  • 个人可以备案企业网站吗深圳做网站哪家公司最好
  • 儿童网站模板免费下载网站的积分系统怎么做的
  • 做动态图片的网站吗wordpress情侣模板
  • 长春建设工程管理中心网站室内装修设计师工资一般多少钱
  • 网页模版网站大连网络设计有限公司
  • 网站开发好就业吗做一个购物商城网站多少钱