-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_3.cpp
More file actions
32 lines (28 loc) · 731 Bytes
/
Copy pathvector_3.cpp
File metadata and controls
32 lines (28 loc) · 731 Bytes
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
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &p1,
const pair<int, int> p2) {
return p1.second < p2.second;
}
void displaySorted(int roll_no[], int marks[], int n) {
vector<pair<int, int>> vec;
for (int i=0; i<n;i++) {
vec.push_back(make_pair(roll_no[i], marks[i]));
}
sort(vec.begin(), vec.end(), sortbysec);
cout << "Roll No: "
<< " "
<< "Marks"
<< endl;
for (int i=0; i<vec.size(); i++) {
cout << vec[i].first << " " << vec[i].second << "\n";
}
}
int main(int argc, char const *argv[])
{
int roll_no[] = {17, 20, 15, 1, 5};
int marks[] = {80, 75, 93, 78, 84};
int n = sizeof(roll_no)/sizeof(roll_no[0]);
displaySorted(roll_no, marks, n);
return 0;
}