hdu 4041 2011北京赛区网络赛B 搜索 ***
直接在字符串上搜索,注意逗号的处理
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
#define pb(a) push_back(a)
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt,cnt;
int pos=,num=,len;
vector<int> vc;
vector<string> ans;
char s[];
void dfs()
{
if(pos>=len) return;
string ss;
while(s[pos]>='a'&&s[pos]<='z')
{
ss.push_back(s[pos]);
pos++;
}
ans.push_back(ss);
int now=num++;
vc.push_back(now);
if(s[pos]=='(')
{
pos++;
dfs();
vc.push_back(now);
while(s[pos]==',')
{
pos++;
dfs();
vc.push_back(now);
}
pos++;
}
else return;
}
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
ans.clear();
vc.clear();
pos=;
num=;
scanf("%s",s);
len=strlen(s); dfs();
printf("%d\n",num-);
for(int i=;i<ans.size();i++){
printf("%s\n",ans[i].c_str());
}
for(int i=;i<vc.size()-;i++){
printf("%d %d\n",vc[i],vc[i+]);
}
printf("\n");
}
}
hdu 4041 2011北京赛区网络赛B 搜索 ***的更多相关文章
- hdu 4044 2011北京赛区网络赛E 树形dp ****
专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***
插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...
- hdu 4043 2011北京赛区网络赛D 概率+大数 **
推出公式为:P = A(2n,n)/(2^(2n)*n!) 但是不会大数,学完java再补
- hdu 4046 2011北京赛区网络赛G 线段树 ***
还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #defi ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- hdu 4035 2011成都赛区网络赛E 概率dp ****
太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...
- hdu 4031 2011成都赛区网络赛A题 线段树 ***
就是不知道时间该怎么处理,想了好久,看了别人的题解发现原来是暴力,暴力也很巧妙啊,想不出来的那种 -_-! #include<cstdio> #include<iostream&g ...
随机推荐
- mybatis动态SQL - like
用'%${name}%'可以实现模糊查询,但会放开SQL注入漏洞. <when test="name != null and name!=''"> AND name l ...
- Java总结(一):封装——Encapsulation
官方定义:一种将抽象性函式接口的实作细节部份包装.隐藏起来的方法.封装可以被认为是一个保护屏障,防止该类的代码和数 据被外部类定义的代码随机访问. 大白话定义:通过getter和setter方法访问私 ...
- jquery.cookie中的操作
http://w3school.com.cn/js/js_cookies.asp jquery.cookie中的操作: jquery.cookie.js是一个基于jquery的插件,点击下载! 创建一 ...
- Sort Transformed Array
Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...
- Xcode 必备插件管理器 http://alcatraz.io
各种小插件,其中写注释用的 VVDocumenter 是必备的!
- Tomcat内存溢出(java.lang.OutOfMemoryError: PermGen space)
Tomcat启动时报如下错误: java.lang.OutOfMemoryError: PermGen space 解决办法: 配置相关内存大小.其中按照启动tomcat的不同方式,分 ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- JavaScript高级程序设计学习笔记--函数表达式
关于函数声明,它的一个重要特征就是函数声明提升,意思是在执行代码之间会读取函数声明,意思是在执行代码之前会先读取函数声明.这就意味着可以把函数声明放在调用它的语句 后面. sayHi(); funct ...
- WinForm相关注意点
1. //this.dgvEmployees.ColumnHeadersDefaultCellStyle.ForeColor = Color.Blue; //dgvEmployees.RowHeade ...
- POJ 2965 The Pilots Brothers' refrigerator
题目链接 题意:一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行.同一列所有的开关都会自动改变状态.要想打开冰箱,要所有开关全部打开才行. 输入:一个4 ...