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

网站上的流动图片怎么做的网络推广app

网站上的流动图片怎么做的,网络推广app,保护区门户网站建设制度,招聘网站模板页题目链接 722. 删除注释 标签 字符串 步骤 Step1. 先将source合并为一个字符串进行处理,中间补上’\n’,方便后续确定注释开始、结束位置。 string combined; for (auto str : source) {combined str "\n"; }Step2. 定义数组 toDel&am…

题目链接

722. 删除注释

标签

字符串

步骤

Step1. 先将source合并为一个字符串进行处理,中间补上’\n’,方便后续确定注释开始、结束位置。

string combined;
for (auto str : source) {combined += str + "\n";
}

Step2. 定义数组 toDel,记录每一个注释开始、结束的位置;进行状态转移。对于 /**/ 类型的注释的结束符 */,如果匹配失败,则需要回退一位。

状态转移表示如下:

s0: if /: goto s1 # match /, change to s1else: goto s0
s1: if /: cut down this line, goto s0 # match //elif *: goto s2 # match /*else: goto s0 # match failed, return to s1
s2: if *: goto s3 # match * in comment; s2 means that the current state is InCommentelse: goto s2
s3: if /: end this comment, goto s0 # match */else: goto s3  # match failed, return to s2

具体的代码部分如下:

for (int i = 0; i < len; i++) {char ch = combined[i];switch (state) {case 0:if (ch == '/') {state = 1;} else {state = 0;}break;case 1:if (ch == '/') { // 出现//,删去此行之后的内容// 找到从当前下标开始的第一个\n,下一次遍历从其之后开始int end = combined.find("\n", i);cmtBegin = i - 1;cmtEnd = end - 1;toDel.push_back({cmtBegin, cmtEnd});state = 0;i = end;} else if (ch == '*') { // 出现/*state = 2;cmtBegin = i - 1;} else {state = 0;}break;case 2:if (ch == '*') {state = 3;} else {state = 2;}break;case 3:if (ch == '/') { // cmtEndstate = 0;cmtEnd = i;toDel.push_back({cmtBegin, cmtEnd});} else { // 匹配*/失败,回退一位state = 2;i--;}break;} 
}

Step3. 遍历 toDel,得到不含注释的中间结果 tmpAns

// 遍历toDel,得到删除注释的中间结果
string tmpAns;
int last = 0;
for (auto p : toDel) {// 下标a和b-1之间的长度:b-atmpAns += combined.substr(last, p.first - last);last = p.second + 1;
}
// 分为toDel.size()+1段的最后一段
tmpAns += combined.substr(last, combined.length() - last);

Step4. 根据 \n 来分割 tmpAns 即可。

vector<string> ans;
int pos = tmpAns.find("\n", 0);
while (pos != string::npos) {if (pos != 0) {ans.push_back(tmpAns.substr(0, pos));}tmpAns.erase(0, pos+1);pos = tmpAns.find("\n", 0);
}

实现代码(C++)

class Solution {
public:vector<string> removeComments(vector<string>& source) {int state = 0;// 合并为一个字符串string combined;for (auto str : source) {combined += str + "\n";}vector<pair<int,int>> toDel;int len = combined.length();int cmtBegin = -1, cmtEnd = -1;for (int i = 0; i < len; i++) {char ch = combined[i];switch (state) {case 0:if (ch == '/') {state = 1;} else {state = 0;}break;case 1:if (ch == '/') { // 出现//,删去此行之后的内容// 找到从当前下标开始的第一个\n,下一次遍历从其之后开始int end = combined.find("\n", i);cmtBegin = i - 1;cmtEnd = end - 1;toDel.push_back({cmtBegin, cmtEnd});state = 0;i = end;} else if (ch == '*') { // 出现/*state = 2;cmtBegin = i - 1;} else {state = 0;}break;case 2:if (ch == '*') {state = 3;} else {state = 2;}break;case 3:if (ch == '/') { // cmtEndstate = 0;cmtEnd = i;toDel.push_back({cmtBegin, cmtEnd});} else { // 匹配*/失败,回退一位state = 2;i--;}break;} }// 遍历toDel,得到删除注释的中间结果string tmpAns;int last = 0;for (auto p : toDel) {tmpAns += combined.substr(last, p.first - last);last = p.second + 1;}tmpAns += combined.substr(last, combined.length() - last);// 根据\n分割vector<string> ans;int pos = tmpAns.find("\n", 0);while (pos != string::npos) {if (pos != 0) {ans.push_back(tmpAns.substr(0, pos));}tmpAns.erase(0, pos+1);pos = tmpAns.find("\n", 0);}return ans;}
};
http://www.shuangfujiaoyu.com/news/29123.html

相关文章:

  • 学网站建设要多少钱常州seo收费
  • 杭州做网站的公司网站域名ip查询
  • 石家庄网站建设推广公司报价百度一下搜索
  • 网页设计页面链接龙岗seo网络推广
  • wordpress建立企业网站人民网今日头条
  • 手机网站建站公司有哪些百度快照怎么优化排名
  • 布吉做棋牌网站建设哪家公司便宜steam交易链接怎么获取
  • 网站建设华科技公司seo关键词排名技巧
  • flash网站建设什么是seo营销
  • 给别人做网站别人违法经营6页面优化算法
  • wordpress网站欣赏软文广告100字
  • 一个网站开发小组推广优化师
  • 学做网站需要什么基础如何用手机制作网站
  • 自己做免费网站的流程栾城seo整站排名
  • 做动态网站还是静态网站网页设计制作网站教程
  • 佳匠网站建设怎么搭建一个网站
  • webform做网站 适应屏幕大小制作公司网站大概多少钱
  • 打鱼网站开发行业关键词分类
  • 淘宝客的免费电影网站怎么做2024年最新一轮阳性症状
  • 开发区网站制作公司游戏优化大师有用吗
  • 做网站插背景图片如何变大新网站怎么做推广
  • 做app找哪个网站百度seo推广计划类型包含
  • 企业门户网站云服务器配置要求网络营销所学课程
  • asp.net 价格查询网站seo优化评论
  • 建设网站服务软文平台
  • 怎么做网站文件验证成人计算机速成培训班
  • wordpress瀑布流风格宁波网络推广优化方案
  • 做网站建设月收入多少营销推广文案
  • 企业官网模板免费seo优化效果
  • 做电影网站许可证seo优化网站优化排名