admin管理员组文章数量:1596328
/* ***********************************************
Author :xryz
Email :523689985@qq
Created Time :4-17 20:52:26
File Name :Eliminate Witches!.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <time.h>
using namespace std;
struct node
{
char str[15];
} n[50001];
queue<int>q;
stack<int>s;
int main()
{
int T,i,j,cnt,len;
char name[16],ss[1000001];
scanf("%d",&T);
while(T--)
{
while(!q.empty()) q.pop();
while(!s.empty()) s.pop();
scanf("%s",ss);
cnt=0;
len=strlen(ss);
j=0;
for(i=0;i<len;i++)
{
if(ss[i]>='a'&&ss[i]<='z')
name[j++]=ss[i];
else
{
if(j!=0)
{
name[j]=0;
j=0;
strcpy(n[++cnt].str,name);
}
if(ss[i]=='(')
{
q.push(cnt);
s.push(cnt);
}
else if(ss[i]==',')
{
if(ss[i-1]!=')')
{
q.push(cnt);
q.push(s.top());
//s.pop();
}
else q.push(s.top());
}
else if(ss[i]==')')
{
if(ss[i-1]!=')')
{
q.push(cnt);
q.push(s.top());
s.pop();
}
else
{
q.push(s.top());
s.pop();
}
}
}
}
if(cnt==0)
{
printf("1\n%s\n",ss);
}
else
{
printf("%d\n",cnt);
for(i=1; i<=cnt; i++)
printf("%s\n",n[i].str);
while(!q.empty())
{
if(q.front()==1&&q.size()==1) break;
printf("%d ",q.front());
q.pop();
printf("%d\n",q.front());
}
}
printf("\n");
}
return 0;
}
版权声明:本文标题:hdu 4041 Eliminate Witches! 栈和队列 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728255957a1151015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论