100722B
在stack里套set,然后每次根据他的操作,在set里操作,把括号hash,插入,输出set的size-1
#include<iostream>
#include<set>
#include<cstdio>
#include<stack>
#define ll long long
#define st set<ll>
using namespace std;
stack<st>s;
ll T,n,tot;
char S[];
int main()
{
cin>>T;
while(T--)
{
cin>>n;
while(!s.empty())s.pop();
for(int i=;i<=n;i++)
{
scanf("%s",S);
if(S[]=='P')
{
st x;x.clear();
x.insert();
s.push(x);
printf("%d\n",);
}
if(S[]=='D')
{
st a;a.clear();
a=s.top();
ll temp=a.size()-;
s.push(a);
printf("%d\n",temp);
}
if(S[]=='U')
{
st a=s.top();s.pop();
st b=s.top();s.pop();
for(st::iterator it=a.begin();it!=a.end();it++)
b.insert(*it);
s.push(b);
printf("%d\n",b.size()-);
}
if(S[]=='I')
{
st a=s.top();s.pop();
st b=s.top();s.pop();
st c;c.clear();
for(st::iterator it=a.begin();it!=a.end();it++)
if(b.count(*it))c.insert(*it);
s.push(c);
printf("%d\n",c.size()-);
}
if(S[]=='A')
{
st a=s.top();s.pop();
st b=s.top();s.pop();
st c;c.clear();
ll sum=;
for(st::iterator it=a.begin();it!=a.end();it++)
{sum*=;sum+=*it;}
sum*=;
b.insert(sum);
s.push(b);
printf("%d\n",b.size()-);
}
}
printf("***\n");
}
return ;
}
100722B的更多相关文章
随机推荐
- 第18章 图元文件_18.1 老式图元文件格式(wmf)
18.1 老式图元文件格式(wmf) (1)创建图元文件:HDC hdcMeta = CreateMetaFile(lpszFile); ①如果lpszFile为NULL则图元文件存储在内存中,如果指 ...
- wamp5设置外网访问方法
1.安装完Wamp5之后,从外网访问网页时存在无法访问问题. 2.phpmyadmin外网没法访问 1.解决办法: 打开wamp的托盘图标(右下角),找到"Config files" ...
- GIT安装和使用
GIT 首先登陆github账号 在本地创建一个文件夹 点击文件夹,右键,选择Git create repository here 操作之后,会生成一个.git文件(这个文件为隐藏文件) 在此 ...
- sql语句常用说明与解析
from: http://www.cnblogs.com/rainman/archive/2013/05/01/3053703.html#m3
- ubuntu下nginx+php5的部署
ubuntu下nginx+php5环境的部署和centos系统下的部署稍有不同,废话不多说,以下为操作记录:1)nginx安装root@ubuntutest01-KVM:~# sudo apt-get ...
- 利用scp 远程上传下载文件/文件夹和ssh远程执行命令
利用scp传输文件 1.从服务器下载文件scp username@servername:/path/filename /tmp/local_destination例如scp codinglog@192 ...
- GridView EmptyDataTemplate 动态显示
以下语句加在GridView.DataBind()之后: Table GridViewTable = ((Table)gvGridView.Controls[]); if (!isSearch) (( ...
- BZOJ 1010 【HNOI2008】 玩具装箱toy
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...
- SQL 2014新特性- Delayed durability
ACID 是数据库的基本属性.其中的D是指"持久性":只要事务已经提交,对应的数据修改就会被保存下来,即使出现断电等情况,当系统重启后之前已经提交的数据依然能够反映到数据库中. 那 ...
- [转]PHP 下使用 ZeroMQ 和 protobuf
FROM : http://www.68idc.cn/help/makewebs/php/20150118175432.html 前言 这个记录总的来说分两部分: 搭建环境. 简单使用教程. 搭建环境 ...