-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasn3.cpp
More file actions
85 lines (67 loc) · 1.4 KB
/
asn3.cpp
File metadata and controls
85 lines (67 loc) · 1.4 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/****************************************************
* Assignment-3 *
* ============ *
* *
* Prepared By: *
* 1. *
* 2. *
* 3. *
* 4. *
* *
* Date of Submission: *
*****************************************************/
#include <bits/stdc++.h>
using namespace std;
const int n = 56;
struct Student{
string name, id;
int marks;
} s[n];
void struct_sort();
bool compare_ids(Student a, Student b);
bool compare_marks(Student a, Student b);
int main()
{
int i;
string t;
freopen("input.txt", "r", stdin);
for(i=0; i<n; i++)
{
getline(cin, s[i].id);
getline(cin, s[i].name);
getline(cin, t);
s[i].marks = atoi(t.c_str());
}
struct_sort();
for(i=0; i<n; i++)
{
cout << setw(15); cout << left << s[i].id;
cout << setw(30); cout << s[i].name;
cout << setw(5); cout << s[i].marks << endl;
}
return 0;
}
void struct_sort()
{
sort(s, s+n, compare_marks);
for(int i=0; i<n-1;)
{
int t, st, en;
st=i;
t=s[i].marks;
while(t==s[i].marks)
{
i++;
}
en=i;
sort(s+st, s+en, compare_ids);
}
}
bool compare_marks(Student a, Student b)
{
return (a.marks > b.marks);
}
bool compare_ids(Student a, Student b)
{
return (a.id < b.id);
}