提交 6e0619f9 编写于 作者: CairBin's avatar CairBin

2022-09-09 新增题解

上级 8e53e59d
/*
* Description:
* @url:https://vjudge.csgrandeur.cn/contest/513104#problem/N
* @author:CairBin
* @since:2022-09-08
*/
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int n;
while(cin >> n)
int t;
while (cin >> t)
{
set<int> num;
int a,b;
for(int i=0; i<n; i++)
set<int> s;
for (int i = 0; i < t; i++)
{
cin >> a >> b;
if(a == 3)
int query, n;
cin >> query;
if (query == 1)
{
auto iter = find(num.begin(), num.end(), b);
if(iter == num.end())
cout << "No" << endl;
else
cout << "Yes" << endl;
cin >> n;
s.insert(n);
}
else if (query == 2)
{
cin >> n;
if (s.find(n) != s.end())
s.erase(s.find(n));
}
else if(a == 2)
num.erase(find(num.begin(), num.end(), b));
else
num.insert(b);
{
cin >> n;
if (s.find(n) != s.end())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
return 0;
}
\ No newline at end of file
}
/*
* Description:
* @url:https://vjudge.csgrandeur.cn/contest/513104#problem/T
* @author:CairBin
* @since:2022-09-09
*/
#include <iostream>
#include <queue>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main()
{
int n;
while(cin >> n)
cin >> n;
while (n--)
{
while(n--)
vector<int> tran;
queue<int> a;
stack<int> b;
int t;
cin >> t;
bool flag = false;
while (t--)
{
int t;
cin >> t;
queue<int> que;
stack<int> stk;
bool flag = false;
while (t--)
string str;
cin >> str;
if (str == "push")
{
string query;
cin >> query;
if (query == "push")
{
int a;
cin >> a;
que.push(a);
stk.push(a);
}
int temp;
cin >> temp;
a.push(temp);
b.push(temp);
}
else if (str == "pop")
{
if (a.empty() || b.empty())
flag = true;
else
{
if (que.empty())
{
cout << "error" << endl;
flag = true;
}
else
que.pop();
if (stk.empty())
cout << "error" << endl;
else
stk.pop();
a.pop();
b.pop();
}
}
}
if(flag)
break;
//输出元素
//队列
while (!que.empty())
if (flag)
cout << "error" << endl
<< "error" << endl;
else
{
while (!a.empty())
{
int p = que.front();
que.pop();
if(que.empty())
cout << p << endl;
else
cout << p << " ";
cout << a.front();
a.pop();
if (!a.empty())
cout << " ";
}
cout << endl;
//栈
vector<int> num;
while (!stk.empty())
while (!b.empty())
{
int p = stk.top();
num.push_back(p);
stk.pop();
tran.push_back(b.top());
b.pop();
}
for (vector<int>::reverse_iterator it = num.rbegin(); it != num.rend(); ++it)
for (vector<int>::reverse_iterator it = tran.rbegin(); it != tran.rend(); it++)
{
if(it+1 == num.rend())
cout << *it << endl;
else
cout << *it << " ";
cout << *it;
if (it != tran.rend())
cout << " ";
}
cout << endl;
}
}
return 0;
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册