当前位置:网站首页>Establishment of zstuacm student information base (completed with linked list)
Establishment of zstuacm student information base (completed with linked list)
2022-07-23 06:03:00 【Rain and cold at night in Xiaoxiang】
Preliminarily master the establishment of linked list , Now let's do another simple linked list operation .
Enter some student information , Including student ID 、 full name 、 achievement .
Now you are required to create a linked list of student libraries with functions .
struct node
{
…
};
struct node * Create_Stu_Doc();
Complete the creation of linked list in the function .
Input
Enter some student information , One line of information for each student , Student number 、 Name and score , Space separates the middle , Both student number and grade are integers , Name is no more than 15 Characters that contain only uppercase and lowercase letters .
If the input line is a non positive integer , End of the said
Output
Create a linked list according to the input order , And output all student numbers and scores higher than the average score , Each row 2 It's an integer , Space separates the middle .
The sample input Copy
1001 xiangwang 90
1002 xiaoli 85
1003 xiaohong 97
1004 xiaoma 76
-1
Sample output Copy
1001 90
1003 97
In fact, there is template code under the original question , But I think STL It is a very convenient and practical tool , So I want to try STL Go and finish the problem
The beginning and other templates are nothing , Until later find_if(begin(),end(),function) function .
The first two parameters are not difficult , The hard one is the last one , Use classes and objects , Even though acm In the game , Classes and objects are used only a few times , It may not even be used , however , As c++ Users of , In the future, classes and objects are the top priority in work , So I decided to write here once .
#include <iostream>
#include<cstdio>
#include<string>
#include<list>
#include<vector>
using namespace std;
// The best way to define a structure is , standard !!!!
typedef struct tag_students
{
int no;
string name;
int grade;
}students;
class CFinderGeaterNum
{
public:
CFinderGeaterNum(int nNum)
{
m_nNum = nNum;
}
bool operator()(const std::list<students>::value_type &value)
{
if (value.grade > m_nNum)
{
return true;
}
return false;
}
private:
int m_nNum;
};
int main()
{
list<students>stu1;
students stu2;
int ave = 0;
while (1)
{
int no1 = 0;// The student ID entered
string name1;// Enter your name
int grade1 = 0;// The grade entered
cin >> no1;
if (no1 <= 0)// If the student number entered <=0, Then push the loop
{
break;
}
cin >> name1 >> grade1;
stu2.no = no1;
stu2.grade = grade1;
stu2.name = name1;
ave = ave + stu2.grade;// averaging , The total number will be divided later
stu1.push_back(stu2);
}
ave = ave / stu1.size() * 1.0;
int xxxxxx = 5;
list<students>::iterator val_begin = stu1.begin();
while (true)
{
list<students>::iterator it = find_if(val_begin, stu1.end(),
CFinderGeaterNum(ave));
if (it != stu1.end())
{
// Find one
cout << it->no <<" " << it->grade << endl;
// Keep looking
it++;
val_begin = it;
continue;
}
else
{
// period
break;
}
}
return 0;
}
//! Pay attention to a big problem , I don't know why acm Use in stl It's easy to exceed the time limit ( Generally speaking stl It's not slow ), So then , The solution is also simple , hold cin And cout Change it into scanf and printf, These two are faster than cin And cout Many times faster !
边栏推荐
猜你喜欢

重置root密码
![[Research Report on the contents, methods, tools and results of information collection]](/img/e2/37606fbd488e55a82c7e6174b892de.jpg)
[Research Report on the contents, methods, tools and results of information collection]

机器学习理论基础
![[jmeter] solution to Chinese garbled response content](/img/ff/3d68a0cc34486e0b6cb35291ce10c0.png)
[jmeter] solution to Chinese garbled response content

利用“HiFolw”快捷制作高校学生返校名单信息生成

Unix programming project - the client based on raspberry pie regularly obtains the temperature and reports it to the server

最简单的scull设备驱动

iptables防火墙

Fiddler script personalized configuration display

APUE进程深层理解fork和execl-程序代码里获取虚拟机IP地址
随机推荐
IA笔记2
Test point, summary of the first day
源码编译!!
[jmeter] solution to Chinese garbled response content
A rough understanding of firewall
数据标注学习总结
CSDN陪伴了我四年本科生活,自己也开始好好记录一下啦
[untitled]
Garbled JS file
On Lora, lorawan and Nb IOT Internet of things technologies
About count=count++
KMP
Iptables firewall
【调研信息搜集的内容,信息搜集的方法,信息搜集的工具,信息搜集结果的利用等调研报告】
多进程常见问题——创建多个线程时访问同一个父线程变量(临界资源)时如何加锁使得共享父线程变量不被重复修改?
Basic process of unit approval
The difference between get request and post request and packet capturing
读《机器学习-周志华》内容摘要
Link: fatal error lnk1104: unable to open the file "opencv_world340.lib"
跨域问题的解决