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

展览网站制作seo优化的内容有哪些

展览网站制作,seo优化的内容有哪些,普通人开网店赚钱吗,监控器材网站建设公司作者:翟天保Steven 版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处 题目描述: 写一个函数 StrToInt,实现把字符串转换成整数这个功能。不能使用 atoi 或者其他类似的库函数。…

作者:翟天保Steven
版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处

题目描述:

写一个函数 StrToInt,实现把字符串转换成整数这个功能。不能使用 atoi 或者其他类似的库函数。传入的字符串可能有以下部分组成:

1.若干空格

2.(可选)一个符号字符('+' 或 '-')

3. 数字,字母,符号,空格组成的字符串表达式

4. 若干空格

转换算法如下:
1.去掉无用的前导空格
2.第一个非空字符为+或者-号时,作为该整数的正负号,如果没有符号,默认为正数
3.判断整数的有效部分:
3.1 确定符号位之后,与之后面尽可能多的连续数字组合起来成为有效整数数字,如果没有有效的整数部分,那么直接返回0
3.2 将字符串前面的整数部分取出,后面可能会存在存在多余的字符(字母,符号,空格等),这些字符可以被忽略,它们对于函数不应该造成影响
3.3  整数超过 32 位有符号整数范围 [−231,  231 − 1] ,需要截断这个整数,使其保持在这个范围内。具体来说,小于 −231的整数应该被调整为 −231 ,大于 231 − 1 的整数应该被调整为 231 − 1
4.去掉无用的后导空格

数据范围:

1.0 <=字符串长度<= 100

2.字符串由英文字母(大写和小写)、数字(0-9)、' '、'+'、'-' 和 '.' 组成

示例:

输入:

"4396 clearlove"

返回值:

4396

说明:

6后面的字符不属于有效的整数部分,去除,但是返回前面提取的有效部分

解题思路:

本题考察算法场景模拟。两种解题思路。

1)遍历法

       首先过滤前置空格;再判断正负号;之后判断连续数字,过程中注意正负极限判断;每找到一个新数字,就把之前的数字*10再累加上去,遍历完即可得到答案。复杂度O(n)。

2)状态机

       基于状态转移矩阵对字符串遍历过程的状态进行分析。

       状态分为4种,空格、符号、数字和无效,对应0123,根据题目条件设立矩阵如下:

\begin{bmatrix} 0 & 1 & 2 & 3\\ 3 & 3& 2 & 3\\ 3& 3& 2 & 3 \end{bmatrix}

  1. 起始状态为0,分析第一行:如果碰到空格,那下一个状态还是0;如果碰到符号,则状态转为1;如果碰到数字,则状态转为2;如果碰到无效字符,状态转为3。
  2. 假设状态转为1,分析第二行:如果碰到空格,即+空格,则无效,因此第二行第一列为3;如果又碰到符号,例如+-,也无效,所以第二行第二列为3;如果碰到数字,例如-3,则状态转为2;碰到无效字符状态转为3。
  3. 假设状态转为2,分析第三行:如果碰到空格,例如+8空格或者8空格,后续均无效,因此第三行第一列为3;如果碰到符号,例如+8+或者8+,后续也是均无效,因此第三行第二列为3;如果碰到数字,例如+89或者89,则后续是有效的,因此第三行第三列为2;无效字符同理无效。
  4. 当状态为2时,对数字进行累加和越界判断;当状态为3时,break退出即可。

       总的来说,状态机就是基于题目要求,将可能发生的情形和状态的转变,以矩阵形式表示,进而解题。复杂度O(n)。

测试代码:

1)遍历法

#include <climits>
class Solution {
public:// 字符串转为整数int StrToInt(string s) {int sign = 1;int idx = 0;int size = int(s.size());// 前空格过滤,过滤完如果没有后续则退出while(idx < size){if(s[idx] == ' ')idx++;elsebreak;}if(idx == size)return 0;// 判断符号,如果没有后续则退出if(s[idx] == '+')idx++;else if(s[idx] == '-'){idx++;sign = -1;}if(idx == size)return 0;// 继续遍历寻找目标数字int result = 0;while(idx < size){// 遇到非数字退出if(s[idx] < '0' || s[idx] > '9')break;// 判断极限if(result > INT_MAX / 10 || (result == INT_MAX / 10 && (s[idx] - '0') >= (INT_MAX % 10)))return INT_MAX;if(result < INT_MIN / 10 || (result == INT_MIN / 10 && (s[idx] - '0') >= -(INT_MIN % 10)))return INT_MIN;// 字符转为数字result = result * 10 + sign * (s[idx] - '0');idx++;}return result;}
};

2)状态机

class Solution {
public:// 字符串转为整数int StrToInt(string s) {// 状态转移矩阵vector<vector<int>> states = {{0,1,2,3},{3,3,2,3},{3,3,2,3},}; // 定义long result = 0;long top = INT_MAX;  long bottom = INT_MIN;int sign = 1;int size = int(s.length());// 状态从0开始int state = 0; for(int i = 0; i < size; ++i){// 空格if(s[i] == ' '){state = states[state][0]; }// 正负号 else if(s[i] == '-' || s[i] == '+'){ state = states[state][1]; if(state == 1){sign = (s[i] == '-') ? -1 : 1;}    }// 数字else if(s[i] >= '0' && s[i] <= '9'){state = states[state][2]; }   // 非法字符else{state = states[state][3]; }// 状态为2时,表明在连续数字状态,进行数字累加if(state == 2){// 数字相加result = result * 10 + s[i] - '0'; // 越界处理result = (sign == 1) ? min(result, top) : min(result, -bottom); }// 状态为3时,说明后续无效,退出即可else if(state == 3)break;}return (int)sign * result;}
};


文章转载自:
http://dinncopaviser.bkqw.cn
http://dinncoinstigate.bkqw.cn
http://dinncokavakava.bkqw.cn
http://dinncohierocratic.bkqw.cn
http://dinncoceeb.bkqw.cn
http://dinncomethodenstreit.bkqw.cn
http://dinncogravicembalo.bkqw.cn
http://dinncofulvous.bkqw.cn
http://dinncorasping.bkqw.cn
http://dinncohandyman.bkqw.cn
http://dinncocubbing.bkqw.cn
http://dinncolampedusa.bkqw.cn
http://dinncozincotype.bkqw.cn
http://dinncoorangutan.bkqw.cn
http://dinncohachure.bkqw.cn
http://dinncoantielectron.bkqw.cn
http://dinncopygmaean.bkqw.cn
http://dinncoanlage.bkqw.cn
http://dinncotopmast.bkqw.cn
http://dinncopromotion.bkqw.cn
http://dinncolognormal.bkqw.cn
http://dinncomegilp.bkqw.cn
http://dinncocreditable.bkqw.cn
http://dinncopercaline.bkqw.cn
http://dinncosanceful.bkqw.cn
http://dinncobigalopolis.bkqw.cn
http://dinncopancratium.bkqw.cn
http://dinncocountermelody.bkqw.cn
http://dinncoexodontics.bkqw.cn
http://dinncogalactosemia.bkqw.cn
http://dinncoanabaptist.bkqw.cn
http://dinncostoa.bkqw.cn
http://dinncostraphanger.bkqw.cn
http://dinncochlorinous.bkqw.cn
http://dinncokibbock.bkqw.cn
http://dinncointransitive.bkqw.cn
http://dinncosomewhat.bkqw.cn
http://dinncootary.bkqw.cn
http://dinncowatchfulness.bkqw.cn
http://dinncoaviatic.bkqw.cn
http://dinncotransplanter.bkqw.cn
http://dinnconewscaster.bkqw.cn
http://dinncotemperamentally.bkqw.cn
http://dinncodegradable.bkqw.cn
http://dinncocuniculus.bkqw.cn
http://dinncoseveralfold.bkqw.cn
http://dinncotrilobite.bkqw.cn
http://dinncogrisly.bkqw.cn
http://dinncoengrossing.bkqw.cn
http://dinncosubah.bkqw.cn
http://dinncophototherapeutics.bkqw.cn
http://dinncoultradian.bkqw.cn
http://dinncoparve.bkqw.cn
http://dinncodecahedral.bkqw.cn
http://dinncoreinscribe.bkqw.cn
http://dinncochitter.bkqw.cn
http://dinncobreviary.bkqw.cn
http://dinncoaeciospore.bkqw.cn
http://dinncoindictable.bkqw.cn
http://dinncoencoffin.bkqw.cn
http://dinncoinvariable.bkqw.cn
http://dinncoroguery.bkqw.cn
http://dinncoinefficiently.bkqw.cn
http://dinncomeningocele.bkqw.cn
http://dinnconimbi.bkqw.cn
http://dinncoseedcake.bkqw.cn
http://dinncourethrectomy.bkqw.cn
http://dinncolimaceous.bkqw.cn
http://dinncoendoscopy.bkqw.cn
http://dinncopalliative.bkqw.cn
http://dinncosantonin.bkqw.cn
http://dinncoobjectivate.bkqw.cn
http://dinncoripstop.bkqw.cn
http://dinnconuclearism.bkqw.cn
http://dinncorugous.bkqw.cn
http://dinncoanelastic.bkqw.cn
http://dinncobillion.bkqw.cn
http://dinncoarcticologist.bkqw.cn
http://dinncoulcerogenic.bkqw.cn
http://dinncobatuque.bkqw.cn
http://dinncobedge.bkqw.cn
http://dinncoatrophied.bkqw.cn
http://dinncofleet.bkqw.cn
http://dinncomild.bkqw.cn
http://dinncophotodynamics.bkqw.cn
http://dinncomanoletina.bkqw.cn
http://dinncounappeasable.bkqw.cn
http://dinncobale.bkqw.cn
http://dinncocortin.bkqw.cn
http://dinncoslope.bkqw.cn
http://dinncocarley.bkqw.cn
http://dinncoelementary.bkqw.cn
http://dinncobotulism.bkqw.cn
http://dinncolaqueus.bkqw.cn
http://dinncolawine.bkqw.cn
http://dinncoestradiol.bkqw.cn
http://dinncowirehead.bkqw.cn
http://dinncoclamshell.bkqw.cn
http://dinncolaundromat.bkqw.cn
http://dinncorifter.bkqw.cn
http://www.dinnco.com/news/106078.html

相关文章:

  • 如何建设高大上的网站百度竞价托管外包代运营
  • 网站制作哪些公司制作湖南网站推广优化
  • 做外贸开通哪个网站好如何设计推广方案
  • 网站制作软件工程师百度竞价广告投放
  • asp.net网站开发案例免费注册网址
  • 表白网站制作生成器搜索引擎优化实训心得
  • 做自己网站彩票百度网盘官网登录首页
  • 顺义哪里有做网站设计的网络整合营销4i原则是指
  • 惠州高端网站建设谷歌网站优化
  • 详述网站建设的过程简答题百度投放广告联系谁
  • 免费商城网站申请网络推广外包想手机蛙软件
  • 扬州做网站的价格长沙关键词优化公司电话
  • 做文献ppt模板下载网站有哪些内容google安卓手机下载
  • 怎么查有做网站的公司如何做营销策划方案
  • 让其他公司做网站应注意什么东莞关键词自动排名
  • 网站建设前期调研公司汇报竞价排名软件
  • 商业网站模板下载头条号权重查询
  • 云市场 wordpress关键词优化软件排行
  • 上海企业网站制作费用职业技能培训班
  • 用网站做淘客怎么做人工智能培训班收费标准
  • 商城网站怎么做的广告公司网上接单平台
  • wordpress站点地图西安seo推广公司
  • vps网站管理助手教程学seo推广
  • 做购物网站适合的服务器百度网址大全免费下载
  • c 网站开发实战百度收录要多久
  • 用模板做网站的方法电商大数据查询平台免费
  • 触摸屏互动网站建设案例怎么开一个网站平台
  • 大余做网站建设电子商务网站建设案例
  • 做网站需要每年交钱吗百度推广怎么弄
  • 深圳网站建设外贸公司排名网站服务器查询工具