Skip to content

Commit bf7617a

Browse files
Give Current Max Problem Solved
1 parent d03ea9f commit bf7617a

5 files changed

+89
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Give Current Max","group":"HackerRank - Final Exam | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/final-exam-a-basic-data-structure-a-batch-05/challenges/get-current-max","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"id":1725208997893,"input":"3\nakib 23 95\njobbar 24 99\nali 25 100\n8\n1\n2\n2\n2\n0 kabir 15 65\n0 asif 55 65\n2\n0 tamim 35 65\n","output":"ali 25 100\njobbar 24 99\nakib 23 95\nEmpty\nkabir 15 65\nkabir 15 65\nasif 55 65\ntamim 35 65\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"GiveCurrentMax"}},"batch":{"id":"787b08a9-4aba-4f18-aa82-36fddeaa689c","size":1},"srcPath":"f:\\Phitron\\3. Basic Data Structures\\Final Exam Problems\\Give_Current_Max.cpp"}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"Give Current Min","group":"HackerRank - Final Exam | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/final-exam-a-basic-data-structure-a-batch-05/challenges/give-max-min","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"4\n10 -10 -5 -20\n10\n1\n2\n2\n2\n2\n0 10\n1\n2\n0 20\n1\n","output":"-20\n-10\n-5\n10\nEmpty\n10\n10\nEmpty\n20\n20\n","id":1725200744076},{"input":"6\n45 -30 83 -99 19 75\n9\n1\n2\n2\n0 32\n0 6\n2\n2\n0 -86\n1\n","output":"-99\n-30\n19\n19\n6\n19\n32\n-86\n-86\n","id":1725200744112}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"GiveCurrentMin"}},"batch":{"id":"066d76d5-6c41-4304-96f9-11423e18e85d","size":1},"srcPath":"f:\\Phitron\\3. Basic Data Structures\\Final Exam Problems\\Give_Current_Min.cpp"}
1+
{"name":"Give Current Min","group":"HackerRank - Final Exam | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/final-exam-a-basic-data-structure-a-batch-05/challenges/give-max-min","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"4\n10 -10 -5 -20\n10\n1\n2\n2\n2\n2\n0 10\n1\n2\n0 20\n1\n","output":"-20\n-10\n-5\n10\nEmpty\n10\n10\nEmpty\n20\n20\n","id":1725200744076},{"id":1725200744112,"input":"6\n45 -30 83 -99 19 75\n9\n1\n2\n2\n0 32\n0 6\n2\n2\n0 -86\n1\n","output":"-99\n-30\n19\n19\n6\n19\n32\n-86\n-86\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"GiveCurrentMin"}},"batch":{"id":"066d76d5-6c41-4304-96f9-11423e18e85d","size":1},"srcPath":"f:\\Phitron\\3. Basic Data Structures\\Final Exam Problems\\Give_Current_Min.cpp"}

Final Exam Problems/.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"files.associations": {
33
"*.embeddedhtml": "html",
44
"*.js": "javascript",
5-
"ostream": "cpp"
5+
"ostream": "cpp",
6+
"iostream": "cpp"
67
}
78
}
96.8 KB
Binary file not shown.
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Student
5+
{
6+
public:
7+
string Name;
8+
int Roll;
9+
int Marks;
10+
Student(string Name, int Roll, int Marks)
11+
{
12+
this->Name = Name;
13+
this->Roll = Roll;
14+
this->Marks = Marks;
15+
}
16+
};
17+
18+
class cmp
19+
{
20+
public:
21+
bool operator()(Student a, Student b)
22+
{
23+
if (a.Marks < b.Marks)
24+
return true;
25+
else if (a.Marks > b.Marks)
26+
return false;
27+
else
28+
return a.Roll > b.Roll;
29+
}
30+
};
31+
32+
int main()
33+
{
34+
int n;
35+
cin >> n;
36+
priority_queue<Student, vector<Student>, cmp> pq;
37+
while (n--)
38+
{
39+
string name;
40+
int roll, marks;
41+
cin >> name >> roll >> marks;
42+
Student obj = Student(name, roll, marks);
43+
pq.push(obj);
44+
}
45+
46+
int q;
47+
cin >> q;
48+
49+
while (q--)
50+
{
51+
int c;
52+
cin >> c;
53+
if (c == 0)
54+
{
55+
string name;
56+
int roll, marks;
57+
cin >> name >> roll >> marks;
58+
Student obj = Student(name, roll, marks);
59+
pq.push(obj);
60+
cout << pq.top().Name << " " << pq.top().Roll << " " << pq.top().Marks << endl;
61+
}
62+
else if (c == 1)
63+
{
64+
if (pq.size() > 0)
65+
{
66+
cout << pq.top().Name << " " << pq.top().Roll << " " << pq.top().Marks << endl;
67+
}
68+
else
69+
cout << "Empty" << endl;
70+
}
71+
else if (c == 2)
72+
{
73+
if (pq.size() > 0)
74+
pq.pop();
75+
if (pq.size() > 0)
76+
{
77+
cout << pq.top().Name << " " << pq.top().Roll << " " << pq.top().Marks << endl;
78+
}
79+
else
80+
cout << "Empty" << endl;
81+
}
82+
}
83+
84+
return 0;
85+
}

0 commit comments

Comments
 (0)