当前位置:网站首页>Zstuacm registration results (complete with STL linked list)
Zstuacm registration results (complete with STL linked list)
2022-07-23 06:02:00 【Rain and cold at night in Xiaoxiang】
Title Description
Teacher Ye wants to register grades with a linked list . There are two messages for each test paper : Student id and grade .
For registration results , It is required that grades with a small student number be registered before grades with a large student number .
Teacher Ye has two operations :
1 a b: Add the student number to the linked list a The result is b Of the students , The title ensures that different papers will not have the same student number .
2 k : Query the... In the current linked list k What are the grades of students , Title assurance k Less than or equal to the length of the current linked list .
Please use the linked list to do this problem !
Input
Enter an integer in the first line Q, Represents the number of operations .
Next input Q That's ok , Each line is (1 a b) perhaps (2 k) Format , Represents the first and second operations respectively .
1 <= k, Q <= 1000
1 <= a <= 1000000000
1 <= b <= 100
Output
For each second operation , Output an integer to represent the k The results of three students
The sample input Copy
3
1 20163266 100
1 20163265 99
2 1
Sample output Copy
99
Tips
Please use a linked list .
Everyone knows the linked list , When I was a freshman, I took a bunch of special Abstract pointers to complete , At that time, I was confused for a long time
( After all, I have felt that there is no pressure on the content of the class for a long time. Suddenly, there is an instant that can't be solved, and the mentality is not very good )
Because the pointer is used , Many students may have a headache when they see pointers or linked lists .
But thank you c++ Added in STL Standard library , Let the code of the linked list become very concise and easy to understand , The best thing is STL The future is available in most cases , This is for novice Xiaobai , Very friendly
**#include <iostream>
#include<cstdio>
#include<algorithm>
#include<list>
using namespace std;
typedef struct students// Define a structure for storing data
{
long long num;
int score;
};
bool cmp(students stu1,students stu2)
// This is list Of sort Required in function , The students are arranged in ascending order //
{
bool flag;
if (stu1.num < stu2.num)
{
return true;
}
else
{
return false;
}
}
int main()
{
int n;
cin >> n;
long long num1;
int search, score1;
list<students>stu1;
struct students stu2;
list<students>::iterator lit;// Pointer to iterator
int flag = 0;
for (int i = 0; i < n; i++)
{
cin >> flag;
if (flag == 1)
{
cin >> stu2.num >> stu2.score;
stu1.push_front(stu2);
}
else
{
cin >> search;
stu1.sort(cmp);//list Medium sort function
lit = stu1.begin();
for (int j = 1; j < search; j++)
{
lit++;
}
cout << lit->score << endl;
}
}
return 0;
}**
边栏推荐
- 读刘润《底层逻辑》摘录
- SNAT and DNAT
- Unittest framework learning (I)
- Common problems of multiple processes - how to lock the same parent thread variable (critical resource) when creating multiple threads so that the shared parent thread variable is not repeatedly modif
- Confused may
- Dom4j解析XML文件,处理来至XML的数据信息
- The difference between get request and post request and packet capturing
- UNIX编程—网络socket
- About the problem of re creation after deleting the module in idea:
- zy:修改主机名
猜你喜欢

两个及其简单的TCPUDP程序,树莓派与pc间的通信

Jmeter上传和下载文件

get请求与post请求的区别以及抓包

01. Introduction to large Internet Architecture
![[jmeter] solution to Chinese garbled response content](/img/ff/3d68a0cc34486e0b6cb35291ce10c0.png)
[jmeter] solution to Chinese garbled response content

UNIX实现IO多路复用之使用poll函数实现网络socket服务端

防火墙知识,原理,设备,厂商调研总结报告

Firewall knowledge, principle, equipment, manufacturer research summary report
![[untitled]](/img/cc/890e190893d099a3efbcccc10a6a3d.png)
[untitled]

Unix programming project - the client based on raspberry pie regularly obtains the temperature and reports it to the server
随机推荐
磁盘管理操作
zstuAcm学生信息库的建立(用链表完成)
vim编辑器的使用
The difference between get request and post request and packet capturing
A rough understanding of firewall
洛谷回文质数 Prime Palindromes
03.大型高并发微服务系统设计
Difference between get request and post request
A little life
Implementing IO multiplexing in UNIX using epoll function to realize network socket server
expect 交互
Apply collections Sort() implements list sorting
源码编译安装LAMP
第四次作业:关于cat,grep,cut,sort,uniq,vim,tr等命令的用法
Disk management operations
Collections的Comparable,Comparator
Source code compilation and installation lamp
读《高效阅读法-最划算的自我投资》有感
RAID磁盘阵列
编程入门2——找最小值