-
Notifications
You must be signed in to change notification settings - Fork 1
/
100000601-00.cpp
77 lines (69 loc) · 1.84 KB
/
100000601-00.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* hint:
* 综合运用了多个 STL
*/
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
using namespace std;
bool is_num(char c)
{
return ('0' <= c && c <= '9');
}
void parse_a_line(vector<int>& nums, const string& line)
{
for (int j = 0; j < line.length(); j++)
{
int tmp = 0;
bool found_num = false;
while (j < line.length() && is_num(line[j]))
{
found_num = true;
tmp = tmp * 10 + line[j] - '0';
j++;
}
if (found_num) nums.push_back(tmp);
}
}
struct cmp
{
bool operator () (pair<int, int> a, pair<int, int> b)
{
if (a.second != b.second) return a.second < b.second;
else return a.first > b.first;
}
};
int main()
{
int n;
while (cin >> n) // for each case
{
getchar(); // clear '\n'
// get task - priority
map<int, int> task_priority;
for (int i = 0; i < n; i++) // for each line
{
string line;
getline(cin, line);
vector<int> nums_in_a_line;
parse_a_line(nums_in_a_line, line);
if (task_priority.find(nums_in_a_line[0]) == task_priority.end())
task_priority[nums_in_a_line[0]] = n;
for (int i = 1; i < nums_in_a_line.size(); i++)
task_priority[nums_in_a_line[i]] = task_priority[nums_in_a_line[0]] - 1;
}
// use priority_queue to output ans
priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> ans;
for (map<int, int>::iterator it = task_priority.begin(); it != task_priority.end(); it++)
ans.push(make_pair(it->first, it->second));
// output ans
while (ans.size())
{
printf("Task%d ", ans.top().first);
ans.pop();
}
}
return 0;
}