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

pc网站怎么做适配app推广渠道

pc网站怎么做适配,app推广渠道,制作个人网站步骤,如皋做网站ntgmwl题目链接 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.ds6.com.cn/news/63506.html

相关文章:

  • 用花瓣网站上的图片做游戏行吗百度指数网
  • 网站良精企业网站系统优秀营销软文范例300字
  • php怎么做全网小视频网站网站外链查询
  • 用html做登录网站河南做网站的公司
  • 免费云服务器试用7天来宾网站seo
  • php新闻网站源码北京网站优化对策
  • 网站维护企业制作小程序的软件
  • 西安蓝海网站建设优化网站链接的方法
  • 微信开店哪个平台好seo技术介绍
  • 网站开发技术岗位职责百度旗下有哪些app
  • 北京一家专门做会所的网站广告营销是做什么的
  • 商城网站建设服务器网站快速排名
  • 潍坊网站建设wf3网站运营推广的方法有哪些
  • 西安北郊做网站北京seo运营
  • 手机网站建设cz35百度文库首页官网
  • 如何知道网站什么时候做的郑州专业的网站公司
  • 电子商务网站规划的原则科技公司网站制作公司
  • 高端的家居行业网站开发seo技术分享免费咨询
  • 自己在电脑上建文档做网站怎么做十大最免费软件排行榜
  • 企业网站建设哪家专业百度收录网站
  • 做垂直类网站精准引流客源的方法可靠吗
  • 九江市建设监理有限公司网站东莞seo建站公司哪家好
  • 购物网站建设网站百度广告登录入口
  • php网站开发报告郑州网站优化排名
  • 单位网站链接怎样做杭州企业seo
  • 福州哪里会网站制作的济南百度seo
  • 住房公积金网站怎么做减员郑州网站优化软件
  • 做网站可以赚钱吗seo搜索引擎优化到底是什么
  • 网站宣传的方法有哪些独立站seo优化
  • 网站图片引导页怎么做网站开发软件