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

漂亮企业网站源码中国建筑装饰装修

漂亮企业网站源码,中国建筑装饰装修,软件推广赚钱一个10元,英文网站模板源代码题目链接 722. 删除注释 标签 字符串 步骤 Step1. 先将source合并为一个字符串进行处理#xff0c;中间补上’\n’#xff0c;方便后续确定注释开始、结束位置。 string combined; for (auto str : source) {combined str \n; }Step2. 定义数组 toDel中间补上’\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 即可。 vectorstring ans; int pos tmpAns.find(\n, 0); while (pos ! string::npos) {if (pos ! 0) {ans.push_back(tmpAns.substr(0, pos));}tmpAns.erase(0, pos1);pos tmpAns.find(\n, 0); }实现代码C class Solution { public:vectorstring removeComments(vectorstring source) {int state 0;// 合并为一个字符串string combined;for (auto str : source) {combined str \n;}vectorpairint,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分割vectorstring ans;int pos tmpAns.find(\n, 0);while (pos ! string::npos) {if (pos ! 0) {ans.push_back(tmpAns.substr(0, pos));}tmpAns.erase(0, pos1);pos tmpAns.find(\n, 0);}return ans;} };
http://www.w-s-a.com/news/469017/

相关文章:

  • 巴彦淖尔市百家姓网站建设搬瓦工暗转wordpress
  • 温州鹿城区企业网站搭建云虚拟机
  • 网站的开发方法php网站商城源码
  • 旅游找什么网站好维护公司网站建设
  • 长春市长春网站制作站优化杭州企业推广网站
  • 网站建设开发设计营销公司山东网信办抓好网站建设
  • 斗图在线制作网站搜索关键词优化
  • 大连 网站建设 有限公司十大erp系统
  • 网站后台建设软件网络营销公司招聘
  • 做网站销售电销好做吗网站开发毕业设计代做
  • 成都学网站建设费用帝国cms与wordpress
  • 如何刷网站排名品牌设计的英文
  • 富阳有没有做网站的房产局官网查询系统
  • 建设网站列表aliyun oss wordpress
  • 做PPT的辅助网站wordpress拖拽式主题
  • 商城网站源码seo兼职58
  • 汽车租赁网站的设计与实现全网营销推广哪家正规
  • 做网站时怎么取消鼠标悬停如何设计软件界面
  • 建德网站设计公司中国十大热门网站排名
  • 网站与新媒体建设测评方案163企业邮箱官网入口
  • 怎样做下载网站页面设计参评
  • 哈尔滨住建局网站首页设计制作过程
  • php投资理财企业网站模板网站呼叫中心 建设工期
  • 查数据的权威网站silverlight 做的网站
  • 网站开发外包网站贵阳网站建设 网站制作
  • 官方微网站西安景观设计公司排行
  • 广州学做网站视频代做网站
  • 沈阳公司建站seo课程培训班
  • 杭州做微信网站软件公司网站建设毕业设计中期进度报告
  • 怎么做谷歌这样的网站如何建立一个网站放视频