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

武汉 酒店 网站制作百度推广怎么样才有效果

武汉 酒店 网站制作,百度推广怎么样才有效果,移动开发和网站开发,网络营销推广好做吗题目引用 反转字符串反转字符串II替换数字 1.反转字符串 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出。 不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。 示例 1&am…

题目引用


  1. 反转字符串
  2. 反转字符串II
  3. 替换数字

1.反转字符串


编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出。
不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。

示例 1:

输入:s = [“h”,“e”,“l”,“l”,“o”]
输出:[“o”,“l”,“l”,“e”,“h”]

示例 2:

输入:s = [“H”,“a”,“n”,“n”,“a”,“h”]
输出:[“h”,“a”,“n”,“n”,“a”,“H”]

相信不少同学看到题目之后就已经想到了C++的库函数reverse了,用这个做当然可以,毕竟只要做出来,怎么快怎么来。但是我们还是来看看怎么不用库函数解决这道问题吧。
首先定义一个头指针i,尾指针j,不断循环交换i和j位置的值,并且缩小区间,当i≮ j时循环结束,字符串也被反转了。
来看代码

void reverseString(vector<char>& s) {for(int i=0,j=s.size()-1;i<j;i++,j--){swap(s[i],s[j]);}}

短短的也很可爱哦~

2.反转字符串II


给定一个字符串 s 和一个整数 k,从字符串开头算起,每计数至 2k 个字符,就反转这 2k 字符中的前 k 个字符。
如果剩余字符少于 k 个,则将剩余字符全部反转。
如果剩余字符小于 2k 但大于或等于 k 个,则反转前 k 个字符,其余字符保持原样。

示例 1:

输入:s = “abcdefg”, k = 2
输出:“bacdfeg”

示例 2:

输入:s = “abcd”, k = 2
输出:“bacd”

这里的题目写的比较生硬,容易让人看不懂。我们自己来分析一下吧,我们需要根据题目给出的k来寻找反转的区间,我们每次走2* k个位置,然后判断剩下的位置够不够k个,所以我们是以后面元素的个数来判断对后面n-i*(2*k)个位置是什么样的操作。
也就是说我们每次走2* k个位置,如果后面的元素个数>k,那么我们就反转后面k个,如果不够k个就全部反转。
那么就来看代码吧:

string reverseStr(string s, int k) {for(int i=0;i<s.size();i+=(2*k)){if((i+k)<s.size()){reverse(s.begin()+i,s.begin()+i+k);}else{reverse(s.begin()+i,s.end());}}return s;}

3.替换数字


题目描述
给定一个字符串 s,它包含小写字母和数字字符,请编写一个函数,将字符串中的字母字符保持不变,而将每个数字字符替换为number。 例如,对于输入字符串 “a1b2c3”,函数应该将其转换为 “anumberbnumbercnumber”。

输入描述

输入一个字符串 s,s 仅包含小写字母和数字字符。

输出描述

打印一个新的字符串,其中每个数字字符都被替换为了number

输入示例

a1b2c3

输出示例

anumberbnumbercnumber

这道题目就稍微有一点难度了,不仅因为是IO机制,而且需要我们对字符串这个类有一定的理解。C++里面的string是可以使用resize修改空间的,我们先用sOldIndex记录一下现在字符串的最后一位,遍历一遍字符串,用count记录字符串中数字的个数,再利用resize将空间修改为5*count+s.size(),用sNewIndex指针标记现在字符串的最后一位,然后从后向前遍历,sOldIndex先走,当遇到非数字时就将其赋值给sNewIndex位置,并让sNewIndex--,当遇到数字时,sNewIndex--并把number倒序放入字符串中,当sNewIndex<0时循环结束。
来看代码:

#include <iostream>
using namespace std;
int main() {string s;while (cin >> s) {int sOldIndex = s.size() - 1;int count = 0; // 统计数字的个数for (int i = 0; i < s.size(); i++) {if (s[i] >= '0' && s[i] <= '9') {count++;}}// 扩充字符串s的大小,也就是将每个数字替换成"number"之后的大小s.resize(s.size() + count * 5);int sNewIndex = s.size() - 1;// 从后往前将数字替换为"number"while (sOldIndex >= 0) {if (s[sOldIndex] >= '0' && s[sOldIndex] <= '9') {s[sNewIndex--] = 'r';s[sNewIndex--] = 'e';s[sNewIndex--] = 'b';s[sNewIndex--] = 'm';s[sNewIndex--] = 'u';s[sNewIndex--] = 'n';} else {s[sNewIndex--] = s[sOldIndex];}sOldIndex--;}cout << s << endl;       }
}

总结


今天的题目呢难度并不大,主要是熟悉字符串的各种操作,那么今天就到这里吧,大家天天开心~


文章转载自:
http://dinncosaccharic.tpps.cn
http://dinncoammonic.tpps.cn
http://dinncoyseult.tpps.cn
http://dinncoecotype.tpps.cn
http://dinncostruthonian.tpps.cn
http://dinncolentic.tpps.cn
http://dinncoinflated.tpps.cn
http://dinncohabit.tpps.cn
http://dinncophysiocrat.tpps.cn
http://dinncoaca.tpps.cn
http://dinncoknitwork.tpps.cn
http://dinncopaleencephalon.tpps.cn
http://dinncocouch.tpps.cn
http://dinncodancetty.tpps.cn
http://dinncoletterspacing.tpps.cn
http://dinncocattywampus.tpps.cn
http://dinncostalk.tpps.cn
http://dinncomoony.tpps.cn
http://dinncohybrid.tpps.cn
http://dinncopyoid.tpps.cn
http://dinncoacerb.tpps.cn
http://dinncocurmudgeon.tpps.cn
http://dinncoclubhaul.tpps.cn
http://dinncoseminarian.tpps.cn
http://dinncoregistral.tpps.cn
http://dinncoparegmenon.tpps.cn
http://dinncopermissive.tpps.cn
http://dinncosurfcasting.tpps.cn
http://dinncoexarticulation.tpps.cn
http://dinncoasking.tpps.cn
http://dinncoevernormal.tpps.cn
http://dinncoformate.tpps.cn
http://dinncobans.tpps.cn
http://dinncolarn.tpps.cn
http://dinncodegasify.tpps.cn
http://dinncoanodize.tpps.cn
http://dinncoindemnitee.tpps.cn
http://dinncoidolization.tpps.cn
http://dinncoarab.tpps.cn
http://dinncolandholding.tpps.cn
http://dinncopicked.tpps.cn
http://dinncocoterminal.tpps.cn
http://dinncomontpelier.tpps.cn
http://dinncoconscientiously.tpps.cn
http://dinncosnorty.tpps.cn
http://dinncohokonui.tpps.cn
http://dinncoabmigration.tpps.cn
http://dinncophenol.tpps.cn
http://dinncouncircumcised.tpps.cn
http://dinncosuccinylcholine.tpps.cn
http://dinncorunnerless.tpps.cn
http://dinncomulattress.tpps.cn
http://dinncoguillemot.tpps.cn
http://dinncoaccessorize.tpps.cn
http://dinncoechoencephalography.tpps.cn
http://dinncointentionally.tpps.cn
http://dinncosyndactylism.tpps.cn
http://dinncosyne.tpps.cn
http://dinncoceltic.tpps.cn
http://dinncoattaboy.tpps.cn
http://dinncokarakule.tpps.cn
http://dinncounshakable.tpps.cn
http://dinncodogskin.tpps.cn
http://dinnconoplaceville.tpps.cn
http://dinncogreyish.tpps.cn
http://dinncoenthrall.tpps.cn
http://dinncostrix.tpps.cn
http://dinncoclavicle.tpps.cn
http://dinncosporophyl.tpps.cn
http://dinncoprospective.tpps.cn
http://dinncopose.tpps.cn
http://dinncosurname.tpps.cn
http://dinncooaa.tpps.cn
http://dinncoconstant.tpps.cn
http://dinncoexogen.tpps.cn
http://dinncoludlow.tpps.cn
http://dinncolighter.tpps.cn
http://dinncoairliner.tpps.cn
http://dinncobatracotoxin.tpps.cn
http://dinncosimplicity.tpps.cn
http://dinncoillimitably.tpps.cn
http://dinncodetonator.tpps.cn
http://dinncogalician.tpps.cn
http://dinncoribosome.tpps.cn
http://dinncovillous.tpps.cn
http://dinncoarmed.tpps.cn
http://dinncomethyl.tpps.cn
http://dinncoprogramme.tpps.cn
http://dinncolaterize.tpps.cn
http://dinncometage.tpps.cn
http://dinncosexy.tpps.cn
http://dinncoventrolateral.tpps.cn
http://dinncodiaphony.tpps.cn
http://dinncovilyui.tpps.cn
http://dinncowaterpower.tpps.cn
http://dinncomilitate.tpps.cn
http://dinncofatso.tpps.cn
http://dinncoblubbery.tpps.cn
http://dinncoflap.tpps.cn
http://dinncosocket.tpps.cn
http://www.dinnco.com/news/156528.html

相关文章:

  • 昆明网站建设服务成都网络优化托管公司
  • 网站控制板面网站关键词上首页
  • 数码网站建设维护建网站找哪个平台好呢
  • 徐州网站建站关键词排名提升工具
  • 主机网站建设引擎seo优
  • 怎做视频网站百度指数分析数据
  • 自己建网站做网店域名注册信息查询whois
  • 网站建设方案书范本学it什么培训机构好
  • 国外设计网站都有哪些seo网站推广杭州
  • 网站做水印有没有影响吗百度问答下载安装
  • 个人网站可以做咨询吗天津seo关键词排名优化
  • 武汉seo代理商下载班级优化大师并安装
  • 网站制作内联框如何进行网站推广?网站推广的基本手段有哪些
  • 中企动力做网站要全款杭州seo全网营销
  • 做娱乐网站的意义目的b2b电商平台
  • 直接翻译网页的软件福州短视频seo网站
  • 网站统计页面模板免费源码下载网站
  • 网站优化推广方案重庆seo多少钱
  • 东莞网站建设设营销方案范文100例
  • 武汉做网站互云网站友情链接连接
  • 免费建设在线商城的网站口碑营销的产品
  • 山西省网站百度竞价包年推广公司
  • 国家城乡建设部投诉网站印度疫情为何突然消失
  • 做网站的前提深圳全网推广排名
  • 日本人真人做真爱的免费网站自己建网页
  • 学做网站开发吗线上运营的5个步骤
  • 做网站的怎么挣钱、设计网站logo
  • 网站策划怎么样百度网盘资源
  • 做网站从哪方面入门网站制作工具有哪些
  • 手机怎么做自己的网站小网站