-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathG_Chat_Order.cpp
57 lines (47 loc) · 1 KB
/
G_Chat_Order.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
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, string>& a,
pair<int, string>& b)
{
return a.first > b.first;
}
void sortMap(map<int, string>& M)
{
// Declare vector of pairs
vector<pair<int, string> > A;
// Copy key-value pair from Map
// to vector of pairs
set<string> duplication;
for (auto& it : M) {
A.push_back(it);
duplication.insert(it.second);
}
// Sort using comparator function
sort(A.begin(), A.end(), cmp);
// Print the sorted value
for (auto& it : A) {
if(duplication.count(it.second) > 0) {
cout << it.second << endl;
duplication.erase(it.second);
}
}
}
int main()
{
map<int, string> chat;
int t;
cin >> t;
string s;
int timeStamp = 0;
while (t--)
{
cin >> s;
chat[timeStamp++] = s;
}
sortMap(chat);
}