zoukankan      html  css  js  c++  java
  • hdu 4041 2011北京赛区网络赛B 搜索 ***

    直接在字符串上搜索,注意逗号的处理

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 #include<map>
     8 using namespace std;
     9 #define MOD 1000000007
    10 #define pb(a) push_back(a)
    11 const int INF=0x3f3f3f3f;
    12 const double eps=1e-5;
    13 typedef long long ll;
    14 #define cl(a) memset(a,0,sizeof(a))
    15 #define ts printf("*****
    ");
    16 const int MAXN=30010;
    17 int n,m,tt,cnt;
    18 int pos=0,num=1,len;
    19 vector<int> vc;
    20 vector<string> ans;
    21 char s[10000010];
    22 void dfs()
    23 {
    24     if(pos>=len) return;
    25     string ss;
    26     while(s[pos]>='a'&&s[pos]<='z')
    27     {
    28         ss.push_back(s[pos]);
    29         pos++;
    30     }
    31     ans.push_back(ss);
    32     int now=num++;
    33     vc.push_back(now);
    34     if(s[pos]=='(')
    35     {
    36         pos++;
    37         dfs();
    38         vc.push_back(now);
    39         while(s[pos]==',')
    40         {
    41             pos++;
    42             dfs();
    43             vc.push_back(now);
    44         }
    45         pos++;
    46     }
    47     else return;
    48 }
    49 int main()
    50 {
    51     int i,j,k;
    52     #ifndef ONLINE_JUDGE
    53     freopen("1.in","r",stdin);
    54     #endif
    55     scanf("%d",&tt);
    56     while(tt--)
    57     {
    58         ans.clear();
    59         vc.clear();
    60         pos=0;
    61         num=1;
    62         scanf("%s",s);
    63         len=strlen(s);
    64 
    65         dfs();
    66         printf("%d
    ",num-1);
    67         for(int i=0;i<ans.size();i++){
    68             printf("%s
    ",ans[i].c_str());
    69         }
    70         for(int i=0;i<vc.size()-1;i++){
    71             printf("%d %d
    ",vc[i],vc[i+1]);
    72         }
    73         printf("
    ");
    74     }
    75 }
  • 相关阅读:
    在Ubuntu下编译WebKit源码--qt
    Ubuntu 编译Webkit --gtk
    windows远程桌面访问ubuntu12.04
    CentOS下SVN服务器的搭建使用
    Centos搭建SVN服务器三步曲
    StringRedisTemplate常用操作
    MySQL中DATETIME、DATE和TIMESTAMP类型的区别
    mysql 时间索引执行计划
    MySQL大文本类型
    API网关原理
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4711241.html
Copyright © 2011-2022 走看看