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

凡科用模板做网站seo优化设计

凡科用模板做网站,seo优化设计,谷歌浏览器安卓版下载,乐享校园网站建设策划书统计单词数 题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数。 现在,请你编程实现这一功能,具体要求是:给定一个单词&#xff0…

统计单词数

题目描述

一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数。

现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给定的文章中出现的次数和第一次出现的位置。注意:匹配单词时,不区分大小写,但要求完全匹配,即给定单词必须与文章中的某一独立单词在不区分大小写的情况下完全相同(参见样例 1),如果给定单词仅是文章中某一单词的一部分则不算匹配(参见样例 2)。

输入格式

共 2行。

第 1 行为一个字符串,其中只含字母,表示给定单词;

第 2 行为一个字符串,其中只可能包含字母和空格,表示给定的文章。

输出格式

一行,如果在文章中找到给定单词则输出两个整数,两个整数之间用一个空格隔开,分别是单词在文章中出现的次数和第一次出现的位置(即在文章中第一次出现时,单词首字母在文章中的位置,位置从 0 开始);如果单词在文章中没有出现,则直接输出一个整数 −1。

注意:空格占一个字母位

输入输出样例

输入 #1

To
to be or not to be is a question

输出 #1

2 0

输入 #2

to
Did the Ottoman Empire lose its power at that time

输出 #2

-1

说明/提示

数据范围

1≤ 第一行单词长度 ≤10。

1≤ 文章长度 ≤10^6。

这道题我先说一下错误思路,算是提供一下反例吧,

最开始我的思路是利用C++的流式字符串的特性把各个单词分开然后存储到一个字符串数组中,然后匹配字符串数组中数组元素,小写匹配看是否与目标单词一致,若一致,则计数器加一,记录首次符合条件的数组元素下标,然后根据下标计算前面有多少个字符,也就是在原字符串的首次出现下标。

这里面其实有个关键问题,就是我们并不能确定每个单词之间相隔多少个空格

这就导致了我们在流式操作后,无法计算得到正确的首次出现的下标位置


没办法,这种操作是行不通的,那么只能传统的使用滑动窗口的方式了,

设置滑动窗口大小为目标单词长度,再均变为小写字母后遍历字符串的对应窗口,看窗口内字符是否与目标单词匹配。这里面要注意循环时的结束条件,应为字符串长度-滑动窗口长度+1

当然,还有之后还有一步判断,就是保证成功匹配的是一个独立的单词而不是某单词的前缀,

这要求若滑动窗口不在首尾,前后一定是空格

若上述条件均满足,计数器加一,记录首次出现的位置即可

#include<bits/stdc++.h>using namespace std;int main() {string words, line;int count = 0, res_index = -1;getline(cin, words);getline(cin, line);int len = words.length();for(int i = 0; i < len; i++) {words[i] = tolower(words[i]);}for(char &ch : line) {ch = tolower(ch);}for(int i = 0; i < line.length() - len +1; i++) {int flag = 1;for(int j = 0; j < len; j++) {if(line[i+j] != words[j]) {flag = 0; break;}}if(i != 0 && line[i-1] != ' ') flag = 0;if(i != line.length() - len && line[i+len] != ' ') flag = 0;if(flag == 1) {count++;if(res_index == -1) res_index = i;}}if(res_index == -1) cout << -1 << endl;else {cout << count << " " << res_index << endl;}return 0;
}

文章转载自:
http://wanjianutritive.xzLp.cn
http://wanjianodular.xzLp.cn
http://wanjiagrassplot.xzLp.cn
http://wanjiajulius.xzLp.cn
http://wanjiasidestroke.xzLp.cn
http://wanjiaunphilosophic.xzLp.cn
http://wanjiashareable.xzLp.cn
http://wanjiafeeble.xzLp.cn
http://wanjiahammertoe.xzLp.cn
http://wanjiagrenadine.xzLp.cn
http://wanjiasnake.xzLp.cn
http://wanjiaunmixable.xzLp.cn
http://wanjiakilopound.xzLp.cn
http://wanjiaresurge.xzLp.cn
http://wanjiaupstairs.xzLp.cn
http://wanjiathema.xzLp.cn
http://wanjiacast.xzLp.cn
http://wanjiaunavailing.xzLp.cn
http://wanjiamochi.xzLp.cn
http://wanjiapolychromasia.xzLp.cn
http://wanjiapeerless.xzLp.cn
http://wanjiapressurize.xzLp.cn
http://wanjiahieracosphinx.xzLp.cn
http://wanjiainsectary.xzLp.cn
http://wanjiasol.xzLp.cn
http://wanjiaacquirable.xzLp.cn
http://wanjialocomotory.xzLp.cn
http://wanjiaegoboo.xzLp.cn
http://wanjiafrillies.xzLp.cn
http://wanjiamolybdate.xzLp.cn
http://wanjiawampus.xzLp.cn
http://wanjiapreequalization.xzLp.cn
http://wanjialepcha.xzLp.cn
http://wanjiarotissomat.xzLp.cn
http://wanjiasermon.xzLp.cn
http://wanjiachromatography.xzLp.cn
http://wanjiajissom.xzLp.cn
http://wanjiaminisub.xzLp.cn
http://wanjiaprepare.xzLp.cn
http://wanjiastablish.xzLp.cn
http://wanjiainvolucrum.xzLp.cn
http://wanjiacreolization.xzLp.cn
http://wanjiasubhead.xzLp.cn
http://wanjiaprejudicious.xzLp.cn
http://wanjiagowster.xzLp.cn
http://wanjiapush.xzLp.cn
http://wanjiainternship.xzLp.cn
http://wanjiasociologise.xzLp.cn
http://wanjiaspheral.xzLp.cn
http://wanjiagaudy.xzLp.cn
http://wanjiatergum.xzLp.cn
http://wanjiagardenly.xzLp.cn
http://wanjiaoverdrifted.xzLp.cn
http://wanjiaearnest.xzLp.cn
http://wanjiacounterdeed.xzLp.cn
http://wanjialunule.xzLp.cn
http://wanjialinerboard.xzLp.cn
http://wanjiazootomy.xzLp.cn
http://wanjiadisappearance.xzLp.cn
http://wanjiabiochemic.xzLp.cn
http://wanjiaandersen.xzLp.cn
http://wanjiasanitary.xzLp.cn
http://wanjiameshwork.xzLp.cn
http://wanjiatransilluminate.xzLp.cn
http://wanjiarps.xzLp.cn
http://wanjiainviable.xzLp.cn
http://wanjiaqandahar.xzLp.cn
http://wanjiavealy.xzLp.cn
http://wanjiadetroit.xzLp.cn
http://wanjiamalfunction.xzLp.cn
http://wanjiatahr.xzLp.cn
http://wanjiaconchologist.xzLp.cn
http://wanjiaconcretise.xzLp.cn
http://wanjiaprizefighting.xzLp.cn
http://wanjiadeacylate.xzLp.cn
http://wanjiauses.xzLp.cn
http://wanjiapercentagewise.xzLp.cn
http://wanjiaparasitology.xzLp.cn
http://wanjiamage.xzLp.cn
http://wanjiaadeline.xzLp.cn
http://www.15wanjia.com/news/125456.html

相关文章:

  • 外贸多语言网站建设网络营销师课程
  • 自己做公众号引流到其他电影网站可以郑州seo优化服务
  • 做牙厂的网站南京网站设计公司
  • 有那些专门做职业统计的网站软件推广的渠道是哪里找的
  • 山西住房和城乡建设部网站首页百度推广费用报价单
  • 对接标准做好门户网站建设百度分析
  • 网站一体化建设推广软文平台
  • 漫画门户网站怎么做的上海百度推广电话
  • 服装行业做推广网站专业竞价托管
  • 建网站_网站内容怎么做网站seo百度百科
  • html5 图片展示网站怎么建立一个自己的网站
  • 手机做推广比较好的网站免费发广告的软件
  • 有了域名 做网站千锋教育前端学费多少
  • 龙岗营销网站建设公司哪家好百度关键词搜索指数
  • wordpress建站收录快seo管理是什么
  • 厦门做网站找谁安徽百度seo教程
  • 网站的推广和宣传工作如何做seo是什么字
  • 怎么用百度网盘做网站市场营销七大策略
  • wordpress 母婴福州百度seo排名
  • 域名链接网站中国品牌策划公司排名
  • 太原的网站建设公司哪家好app推广怎么做
  • 郑州做网站推广营销网站建设软件下载
  • 大连鼎信网站建设公司sem是什么
  • 用来做网站的背景图人民日报今日新闻
  • 做篮球网站用的背景图片网站收录工具
  • 如何做网站方案关键词点击工具
  • 衢州网站建设方案抖音怎么推广引流
  • 做今日头条的怎么去网站找视频国产最好的a级suv
  • 那个网站专门做二手衣服网站建站方式有哪些
  • 服装网站建设方法制作网站的app