当前位置:网站首页>ZCMU--1367: Data Structure
ZCMU--1367: Data Structure
2022-06-26 17:42:00 【Little why】
Description
Give a set , Initially empty , Conduct N operations , There are three types of operations :
1 Add an element to the collection , If it already exists in the collection , There is no need to add again
2 Remove an element from the collection , If the element does not exist in the collection , You do not need to delete
3 Determine the rank of the element in the set ( The youngest is the eldest ), If the element does not exist, please output :"sorry"( No double quotes )
Input
Multiple sets of test data
Each group 1 That's ok :1 It's an integer N, Indicates the number of operations .(2<=N<=10000)
The first 2 - (N+1) That's ok : Each row 2 It's an integer k and s Corresponding to the mode of operation and the element to be operated (1<=k<=3,1<=s<=1000000)
Output
Corresponding to each operation 3, Give the corresponding results
Sample Input
8
3 1
2 1
1 1
1 1
1 2
3 2
2 2
3 2
5
1 1
1 100
1 1000000
2 99999
3 1000000
Sample Output
sorry
2
sorry
3
analysis : Find out if the element exists , We can use arrays to quickly determine , But who is in the back row , violence 1~N The traversal must have timed out , So we have to use set To store , Then use the iterator to traverse , Initial settings c=1, It means who is in the row , Traverse ,c++, Until you find the element , Output c Is the rank of the element in the collection .
#include <bits/stdc++.h>
using namespace std;
int a[1000005]; // Used to directly determine whether an element exists
int main()
{
int n,z,p,c;
while(~scanf("%d",&n)){
set<int>st;
set<int>::iterator it; // iterator , Prepare for the next ranking
memset(a,0,sizeof(a)); // initialization 0
while(n--){
c=1; // Who is the oldest
scanf("%d%d",&z,&p);
if(z==1){ // Instructions 1
if(a[p]==0) st.insert(p),a[p]=1;// If the element does not exist , Deposit in set, also a[p] Turn into 1
}else if(z==2){ // Instructions 2
if(a[p]==1){ // If it exists, delete it
st.erase(st.find(p)); // Delete
a[p]=0; //a[p] Set as 0, The element no longer exists
}
}else if(z==3){
if(a[p]==1){ // There is
for (it=st.begin();it!=st.end();it++){ // Iterator traversal
if(*it==p){ //*it Indicated value
printf("%d\n",c); // Found the element , Just output the ranking
break;
}
c++; // Did not find , ranking ++
}
}else printf("sorry\n"); //a[p]=0, The element does not exist , Direct output sorry
}
}
st.clear();
}
return 0;
}边栏推荐
- Ndroid development from introduction to mastery Chapter 2: view and ViewGroup
- LeetCode——226. 翻转二叉树(BFS)
- 【动态规划】剑指 Offer II 091. 粉刷房子
- Play with Linux and easily install and configure MySQL
- LeetCode——226. 翻轉二叉樹(BFS)
- Turtle cartography
- 【Unity】在Unity中使用C#执行外部文件,如.exe或者.bat
- How sparksql returns a specific day of the week by date -dayofweek function
- SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
- 丰富专业化产品线, 江铃福特领睿·极境版上市
猜你喜欢

Various types of gypsum PBR multi-channel mapping materials, please collect them quickly!

Over the weekend: 20000 words! Summary of JVM core knowledge, 18 serial cannons as a gift

类型多样的石膏PBR多通道贴图素材,速来收藏!

Platform management background and merchant menu resource management: Design of platform management background data service

Introduction to distributed cache / cache cluster

Byte interview: two array interview questions, please accept

Here comes the hero League full skin Downloader

Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation

背包问题求方案数

Leetcode - 226. Retourner l'arbre binaire (bfs)
随机推荐
Discussion: the next generation of stable coins
Inspirational. In one year, from Xiaobai to entering the core Department of Alibaba, his counter attack
MySQL index
Live broadcast preview | how can programmers improve R & D efficiency? On the evening of June 21, the video number and station B will broadcast live at the same time. See you or leave!
如何将应用加入到deviceidle 白名单?
Record the use process of fenics
Ndroid development from introduction to mastery Chapter 2: view and ViewGroup
MySQL exports all table indexes in the database
Number of solutions for knapsack problem
Preparing for the Blue Bridge Cup and ccf-csp
js强制转换
Microservice architecture practice: user login and account switching design, order query design of the mall
ZCMU--1367: Data Structure
一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
How does Guosen Securities open an account? Is it safe to open a stock account through the link
清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!
sparksql如何通过日期返回具体周几-dayofweek函数
[ten thousand words summary] starting from the end, analyze in detail how to fill in the college entrance examination volunteers
Necessary decorator mode for 3 years' work
玩轉Linux,輕松安裝配置MySQL