当前位置:网站首页>Input the records of 5 students (each record includes student number and grade), form a record array, and then output them in order of grade from high to low The sorting method adopts selective sortin
Input the records of 5 students (each record includes student number and grade), form a record array, and then output them in order of grade from high to low The sorting method adopts selective sortin
2022-07-26 06:21:00 【When can the dead wood spring】
subject ( Software essence P109 topic 12):
Input 5 A student's record ( Each record includes student number and grade ), Form a record array , Then output in the order of high to low grades . The sorting method adopts selective sorting
Code implementation :
/* Input 5 A student's record ( Each record includes student number and grade ), Form a record array , Then output in the order of high to low grades . The sorting method adopts selective sorting */
#include<iostream>
using namespace std;
const int size = 5;
typedef struct {
int id;
int score;
}Student;
void selectSort(Student* students, int n) {
for (int i = 0; i < n - 1; ++i) {
Student temp = students[i];
int loc = i;
for (int j = i + 1; j < n; ++j) {
if (students[j].score > students[loc].score) {
loc = j;
}
}
if (loc != i) {
students[i] = students[loc];
students[loc] = temp;
}
}
}
int main() {
Student students[size];
students[0] = {
0, 60};
students[1] = {
1, 70};
students[2] = {
2, 90};
students[3] = {
3, 30};
students[4] = {
4, 50};
selectSort(students, size);
for (int i = 0; i < size; ++i) {
cout << students[i].id << "\t" << students[i].score << endl;
}
return 0;
}
Running results :

边栏推荐
- Embedded sharing collection 14
- VRRP protocol and experimental configuration
- What is KVM? What is KVM virtual machine?
- If I want to listen to Jay Chou with you, I want you to listen to my whole youth
- Age is a hard threshold! 42 years old, Tencent level 13, master of 985, looking for a job for three months, no company actually accepted!
- Database SQL language practice
- Taobao pinduoduo Tiktok 1688 Suning taote jd.com and other keyword search commodity API interfaces (keyword search commodity API interface, keyword search commodity list interface, classification ID s
- [day_040421] calculate candy
- 2022年下半年系统集成项目管理工程师(软考中级)报名条件
- 【pytorch】微调技术
猜你喜欢

CV (1)- Introduction

"Recursive processing of subproblems" -- judging whether two trees are the same tree -- and the subtree of another tree
![[MySQL from introduction to proficiency] [advanced chapter] (VI) storage engine of MySQL tables, comparison between InnoDB and MyISAM](/img/19/ca3a5710ead3c5b9a222a8ae4ecb37.png)
[MySQL from introduction to proficiency] [advanced chapter] (VI) storage engine of MySQL tables, comparison between InnoDB and MyISAM

Leetcode:934. The shortest Bridge

Using dynamic libraries in VS

Interpretation of TPS motion (cvpr2022) video generation paper

Upgrade appium automation framework to the latest 2.0

Modifiers should be declared in the correct order
![[day_060423] no two](/img/2b/5bcb3e089a3157fe72a50ddb767e63.png)
[day_060423] no two

What is the concept and purpose of white box testing? And what are the main methods?
随机推荐
【Day_05 0422】连续最大和
Distributed | practice: smoothly migrate business from MYCAT to dble
【Day04_0421】C语言选择题
Sequential action localization | fine grained temporal contrast learning for weak supervised temporal action localization (CVPR 2022)
CV (1)- Introduction
[day_060423] convert string to integer
Understanding the mathematical essence of machine learning
【Day03_0420】C语言选择题
nuxt 配置主题切换
Interpretation of TPS motion (cvpr2022) video generation paper
Flex layout
Latex同时合并表格的多行多列
Age is a hard threshold! 42 years old, Tencent level 13, master of 985, looking for a job for three months, no company actually accepted!
VS中使用动态库
K. Link with Bracket Sequence I dp
[pytorch] CNN practice - flower species identification
YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
Solutions to the failure of copy and paste shortcut keys
Practice operation and maintenance knowledge accumulation
[day_060423] no two