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

免费注册论坛怎么给网站做优化

免费注册论坛,怎么给网站做优化,wordpress 打开空白,jsp网站开发论文2017目录 1. 实验内容及上机实验所用平台1.1 实验内容1.2 实验平台软件 2. 流程图3. 源代码4. 用例测试5. 实验总结 1. 实验内容及上机实验所用平台 1.1 实验内容 【问题描述】 给定两个字符串 s1 和 s2,求最长的 s1 前缀 ss 使得 ss 为 s2 的最长后缀,输出…

目录

  • 1. 实验内容及上机实验所用平台
    • 1.1 实验内容
    • 1.2 实验平台软件
  • 2. 流程图
  • 3. 源代码
  • 4. 用例测试
  • 5. 实验总结

1. 实验内容及上机实验所用平台

1.1 实验内容

【问题描述】
给定两个字符串 s1s2,求最长的 s1 前缀 ss 使得 sss2 的最长后缀,输出该字符串和其长度。
【输入形式】
输入的每个测试用例由两行构成,第一行为 s1,第二行为 s2。你可以假设所有字母都为小写字母。
【输出形式】
每个测试用例的输出由单行组成,其中包含最长的字符串,该字符串是 s1 的前缀和 s2 的后缀,后面跟着该前缀的长度。如果最长的此类字符串是空字符串,则输出应为 0s1s2 的长度最多为 50000
【样例输入】
aaariemann
marjorieaaa
【样例输出】
aaa 3
【样例说明】
输入的第一行字符串s1=‘aaariemann’,第二行字符串s2=‘marjorieaaa’。s1的前缀和s2的后缀最长相等字符串为aaa,因此输出aaa 3,而不是a 1。

1.2 实验平台软件

Dev-C++.

2. 流程图

在这里插入图片描述

3. 源代码

需要先在源代码目录下新建 in.txt 文件,在此文件下输入要测试的数据。

#include <iostream>
#include <string>
using namespace std;void getnext(string t, int *next) {	// 求合并串 t 的 next int j = 0, k = -1, len_t = t.length();next[0] = -1;	// 第一个 next 默认为 -1while (j < len_t) {if (k == -1 || t[j] == t[k]) {	// 若 k 为 -1 或者字符相同,j、k 后移 j++; k++;next[j] = k;}else k = next[k];	// 字符不同时,k 回退 }
}int main() {freopen("in.txt", "r", stdin);string s, t;int i = 0, len_s, len_t, len;while (cin >> s >> t) {cout << "\t第2题 - 找出最长串及其长度\n\n";//cout << "--------------------------------------------------------------\n\n";printf("[%d] 样例输入:%s %s\n\n", ++i, s.c_str(), t.c_str());printf("[%d] 样例输出:", i);len_s = s.length();len_t = t.length();len = len_s + len_t;t = s + t;	// 合并两个串 int *next = new int[len + 1];getnext(t, next);	// 计算合并串 t 的 next 值 while (next[len] > len_s || next[len] > len_t) len = next[len];	// 最长串的长度不能超过给定两个串的任何一个的长度 if (next[len] != 0) {	// 若 next 值不为 0,则输出串 s1 的前缀及其长度 for (int j = 0; j < next[len]; j++) cout << s[j];cout << " " << next[len] << endl;}else cout << "0\n";	// 否则没有找到最长串,输出 0 cout << "\n\n==============================================================\n\n";}cout << "9个样例输出完毕!\n\n";freopen("CON", "r", stdin);	// 为了可直接查看exe可执行文件,需要将权限返回键盘 system("pause");return 0;
}

4. 用例测试

in.txt 的测试用例如下:

clinton
homerriemann
marjorieaaaa
aaaaaaaaababa
cdefababaworkhardwo
woabcdefgfedcba
althoughthisisthetruthfedcbaabcdefabcdefgabcdef
abcdefgabcdefsomeone
thisisaongsentenceselizabethlistenedinsilence,butwasnotconvinced.theirbehaviourattheassemblyhadnotbeencalculatedtopleaseingeneral;andwithmorequicknessofobservationandlesspliancyoftemperthanhersister,andwithajudgment,too,unassailedbyanyattentiontoherself,shewasverylittledisposedtoapprovethem.theywereinfactveryfineladies,notdeficientingoodhumourwhentheywerepleased,norinthepowerofbeingagreeablewheretheychoseit;butproudandconceited.theywereratherhandsome,hadbeeneducatedinoneofthefirstprivateseminariesintown,hadafortuneoftwentythousandpounds,wereinthehabitofspendingmorethantheyought,andofassociatingwithpeopleofrank;andwerethereforeineveryrespectentitledtothinkwellofthemselves,andmeanlyofothers.theywereofarespectablefamilyinthenorthofEngland;acircumstancemoredeeplyimpressedontheirmemoriesthanthattheirbrother'sfortuneandtheirownhadbeenacquiredbytrade.Mr.Bingleyinheritedpropertytotheamountofnearlyanhundredthousandpoundsfromhisfather,whohadintendedtopurchaseanestate,butdidnotlivetodoit.--mr.Bingleyintendeditlikewise,andsometimesmadechoiceofhiscounty;butashewasnowprovidedwithagoodhouseandthelibertyofamanor,itwasdoubtfultomanyofthosewhobestknewtheeasinessofhistemper,whetherhemightnotspendtheremainderofhisdaysatNetherfield,andleavethenextgenerationtopurchase.Hissisterswereveryanxiousforhishavinganestateofhisown;butthoughhewasnowestablishedonlyasatenant,missBingleywasbynomeansunwillingtopresideathistable,norwasmrs.Hurst,whohadmarriedamanofmorefashionthanfortune,lessdisposedtoconsiderhishouseasherhomewhenitsuitedher.mr.bingleyhadnotbeenofagetwoyears,whenhewastemptedbyanaccidentalrecommendationtolookatNetherfieldHouse.Hedidlookatitandintoitforhalfanhour,waspleasedwiththesituationandtheprincipalrooms,satisfiedwithwhattheownersaidinitspraise,andtookitimmediately.
thoughnodispositioncouldofferagreatercontrasttohisown,andthoughwithhisownheneverappeareddissatisfied.

在这里插入图片描述

5. 实验总结

这道题目其实就是找串的 next 值,只要将两个串合并来找就可以了。但是要注意的是 next 值最大的不一定是答案,因为在合并后,可能会使得前缀和后缀相同的长度多余两个串的其中一个的长度,比如两个串的元素都一样。所以还要判断当 next 值多余给定串 s1 或者 s2 的长度后,要进行回溯。

http://www.zhongyajixie.com/news/32343.html

相关文章:

  • 社交网站上的商城怎么做泰安网站优化公司
  • 自己做网站 空间怎么买网站google搜索优化
  • 做网站需要的素材照片新闻发稿渠道
  • 对个人做swot分析的网站网页设计与制作代码成品
  • 龙岩网站优化seo工具包
  • 做相册的网站(网易上海关键词优化报价
  • 3g版网站制作宁波seo的公司联系方式
  • 重庆市工程建设造价信息网官网seo优化软件免费
  • 南通市建设局网站最近一周新闻大事摘抄
  • 网站建设外包价格阿里云建站费用
  • 电商网站网址大全cpa游戏推广联盟
  • wordpress 修改文章作者优化疫情二十条措施
  • 网站做百度推广为什么没人咨询互联网推广公司
  • 如何在360做网站SEO哪里可以引流到精准客户呢
  • 互联网公司十大排名南宁seo服务优化
  • 手机网站 开发者模式湖南网站建设推广
  • 网站的备案all营销软文写作
  • 做图片带字的网站投放广告的网站
  • 鞍山诺亚人才网关键词优化和seo
  • 请人代做谷歌外贸网站东莞网站推广企业
  • 制作网站公司哪里好什么是网络营销战略
  • 安阳网站建设公司出租车公司seo招聘
  • 免费购物商城网站建设自己建网站要多少钱
  • 杭州做网站的好公司哪家好新东方留学机构官网
  • 医院网站 功能热搜榜排名今日
  • 喀什网站建设百度推广官网优化包括什么内容
  • 视频主持网站建设怎么做产品推广平台
  • 企业邮箱格式怎么写才正确厦门seo屈兴东
  • 日本优秀设计网站sem是什么意思的缩写
  • 重庆做企业网站痘痘该怎么去除效果好