-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentnumSort.cpp
47 lines (43 loc) · 929 Bytes
/
studentnumSort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
using namespace std;
struct student
{
char name[10];
int num;
};
int main()
{
student list[20] = {};
student *pt;
int i, n, tmp = 0;
char temp[10];
pt = list;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> pt[i].num;
cin >> pt[i].name;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (list[i].num < list[j].num)
{
tmp = list[i].num;
list[i].num = list[j].num;
list[j].num = tmp;
for (int k = 0; k < 10; k++)
{
temp[k] = list[i].name[k];
list[i].name[k] = list[j].name[k];
list[j].name[k] = temp[k];
}
}
}
}
for (i = 0; i < n; i++)
{
cout << pt[i].num << ' ' << pt[i].name << endl;
}
}