zoukankan      html  css  js  c++  java
  • 正则问题

    字符串处理,采用递归的方法

    需要注意的是最后两个测试数据的括号是不匹配的,这要求我们在proc函数处理完之后,如果tmp(记录括号的字符串变量)的size大于0时,直接把tmp拉进去递归

    #include <stdio.h>
    #include <memory.h>
    #include <math.h>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <set>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <map>
    
    #define I scanf
    #define OL puts
    #define O printf
    #define F(a,b,c) for(a=b;a<c;a++)
    #define FF(a,b) for(a=0;a<b;a++)
    #define FG(a,b) for(a=b-1;a>=0;a--)
    #define LEN 3000
    #define MAX 0x06FFFFFF
    #define V vector<int>
    
    using namespace std;
    
    int  proc(string s){
    //    puts(s.c_str());
        int inKH=0,i;
        string tmp; 
        int cnt=0;
        vector<int> v;
        for(i=0;i<s.size();i++){
            if(s[i]=='(') inKH++;
            if(s[i]==')'){
                inKH--;
                if(inKH==0){
                    cnt+=proc(tmp.substr(1,tmp.size()-1));
                    tmp="";
                    continue;
                }
            }
            if(inKH){
                tmp+=s[i];
                continue;
            } 
            if(s[i]=='x'){
                cnt++;
            }else if(s[i]=='|'){
                v.push_back(cnt);
                cnt=0;
            }
        }
        if(tmp.size())
            cnt+=proc(tmp.substr(1,tmp.size()-1));
        v.push_back(cnt);
        return * max_element(v.begin(),v.end());
    }
    
    int main(){
    //    freopen("D:/CbWorkspace/blue_bridge/正则问题.txt","r",stdin);
        char buf[200];
        gets(buf);
        string s(buf);
        printf("%d",proc(s));
        return 0;
    }
  • 相关阅读:
    linux远程桌面连接 VNC Server
    linux内核 mtd分区
    STC15控制数码管 38译码器
    DS12C887实时时钟
    printf打印字节调试
    LED 控制卡 单元板 接口引脚定义
    linux守护进程start-stop-daemon启动服务
    相机速率计算
    CodeWarrior IDE烧写介绍
    让 Web 站点崩溃最常见的七大原因
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8458083.html
Copyright © 2011-2022 走看看