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 ...
随机推荐
- discuz内置常用CSS代码分析
CSS多IE下兼容HACK写法 所有 IE浏览器适用:.ie_all .foo { ... } IE6 专用:.ie6 .foo { ... } IE7 专用:.ie7 .foo { ... } IE ...
- POJ 3903
http://poj.org/problem?id=3903 这个题目是一个求最长递增子序列,这个只是求长度而已,所以可以用LIS 所谓的LIS也就是用二分优化来减少时间而已,而且其只能求出最长的序列 ...
- 在Py文件中引入django环境
复制manage.py中的相关代码即可并将文件置于Project文件夹(与manage.py同位置)下 示例: #! /usr/bin/env python # -*- coding:utf- -*- ...
- Django~automated tests
def xx(): 冒号下一行要缩进 ATD http://blog.csdn.net/doupei2006/article/details/7657547 http://www.jb51.net/a ...
- K3中添加的一条新数据,其在数据库中的位置
最近研究将K3系统与生产管理系统结合起来,减少工作量,但如何确定其各自后台数据库的构成,其对应数据各自位于那张表内,总结了一下: 1.从百度搜索,查看表结构,然后找到目标表 另:K3数据库中单独 ...
- 【leetcode】atoi (hard) ★
虽然题目中说是easy, 但是我提交了10遍才过,就算hard吧. 主要是很多情况我都没有考虑到.并且有的时候我的规则和答案中的规则不同. 答案的规则: 1.前导空格全部跳过 “ 123” ...
- 【DPM】Deformable Part Models matlab代码在windows下的调试过程
我下载的是voc-release5 1.按照这篇文章,都操作了一遍:http://blog.csdn.net/pozen/article/details/7023742#quote 2.运行demo不 ...
- SQL语句题库
一. 填空题 Not Only SQL数据库 泛指 非关系型数据库 . SYS和SYSTEM用户都是Oracle 的系统用户,它们都使用SYSTEM表空间,其中 sys 拥有更大的权限. O ...
- 142. Linked List Cycle II
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...
- UDP-C#代码
新建两个控制台应用程序,一个是服务端,一个是客户端. 1.服务端代码 using System; using System.Collections.Generic; using System.Linq ...