当前位置:网站首页>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;
}边栏推荐
- 【推荐系统学习】推荐系统架构
- ZCMU--1367: Data Structure
- Rich professional product lines, and Jiangling Ford Lingrui · Jijing version is listed
- Over the weekend: 20000 words! Summary of JVM core knowledge, 18 serial cannons as a gift
- Number of solutions for knapsack problem
- How about opening an account at Guojin securities? Is it safe?
- LeetCode——226. Flip binary tree (BFS)
- Implementation of MySQL master-slave architecture
- Problems encountered this week
- Play with Linux and easily install and configure MySQL
猜你喜欢

Microservice architecture practice: business management background and SSO design: SSO design

Troubleshooting ideas that can solve 80% of faults!

背包问题求方案数

Demonstrate to Xiaobai the case of sub database and sub table

Distributed Architecture Overview

SIGIR 2022 | University of Hong Kong and others proposed the application of hypergraph comparative learning in Recommendation System

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!

物联网协议的王者:MQTT

Daily record 2

清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!
随机推荐
Technical scheme design of chain game system development - NFT chain game system development process and source code
Platform management background and merchant menu resource management: Design of platform management background data service
How about opening an account at Guojin securities? Is it safe?
Some explanations for latex CJK
Leetcode - 226. Retourner l'arbre binaire (bfs)
COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
Leetcode 1170. Frequency of occurrence of the minimum letter of the comparison string (yes, solved)
[dynamic planning] Jianzhi offer II 091 Paint the house
In those years, interview the abused red and black trees
[uniapp] the uniapp mobile terminal uses uni Troubleshooting of navigateback failure
mysql Add column 失败 因为之前有数据,不是默认null 不行
【代码随想录-动态规划】T583、两个字符串的删除操作
Here comes the hero League full skin Downloader
vue--vuerouter缓存路由组件
Inspirational. In one year, from Xiaobai to entering the core Department of Alibaba, his counter attack
Basic requirements: 7 problems in singleton mode
VSCode使用 - Remote-SSH 配置说明
halcon之区域:多种区域(Region)特征(5)
What does the equals method compare? Who told you
QPushButton 样式使用示例(以及按钮setmenu添加下拉菜单的方法)