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

自己做网站可以上传软件下载成都seo优化外包公司

自己做网站可以上传软件下载,成都seo优化外包公司,app和网站开发人员工作职责,广告设计公司标志题目描述 求采用顺序结构存储的串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://www.cadmedia.cn/news/7694.html

相关文章:

  • 电子商务平台的发展趋势百度网站排名优化软件
  • vi标识设计公司seo短视频发布页
  • 做有色金属哪个网站好sem竞价推广公司
  • 改善网站建设小说引流推广
  • 济南网站优化收费标准培训体系包括四大体系
  • 描述建设一个网站的具体流程软件开发外包
  • 厦门app网站建设好123上网主页
  • 为什么要做网站建设软文广告图片
  • 手机网站建设哪家公司好网站seo博客
  • 建立网站方法国家市场监管总局
  • 怎么免费建立自己的网站平台搜索引擎是什么
  • 目标网站上做关键字布局全球搜索引擎排名2022
  • 吴江建设局网站打不开百度一下百度网页版主页
  • 网站建设技术架构十大教育培训机构排名
  • 永州市建设工程质量安全监督站官方网站市场推广方案怎么写
  • 外贸网站购买云服务器多少钱seo站内优化培训
  • 织梦论坛源码网站功能优化的方法
  • 网站建设 艺麟盛世百度指数的数据怎么导出
  • 张家口做网站多少钱自动收录网
  • 国外网站建设的步骤推广方案应该有哪些方面
  • 企业seo网站推广seo排名优化价格
  • 代理网站建设公司小江seo
  • 佛山网站建设企业推荐软件开发培训中心
  • 建设网站工作室什么软件可以发帖子做推广
  • 长治企业网站建设价格如何把品牌推广出去
  • 中国机械加工网价位seo网页优化工具
  • 做网站四百全包网站推广在线
  • 正规的现货交易平台seo团队管理系统
  • 网站建设公司 跨界鱼科技专业谷歌sem推广
  • 网站建设的知识和技能网络营销文案策划