-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteque.cpp
More file actions
53 lines (51 loc) · 1.69 KB
/
Copy pathteque.cpp
File metadata and controls
53 lines (51 loc) · 1.69 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
#include <iostream>
#include <map>
#include <string>
int main(void){
int commands;
int nextNumber;
float max, min, mid;
max = min = 0;
mid = 10;
std::map<float, int> teque;
std::string nextCommand;
std::cin >> commands;
for(int i = 0; i < commands; i++){
std::cin >> nextCommand >> nextNumber;
if(nextCommand == "push_back"){
max += 10;
std::cout << "max" << max << nextNumber << std::endl;
teque.insert(std::pair<float, int>(max, nextNumber));
std:: cout << teque.find(10)->second << std::endl;
}
else if(nextCommand == "push_front"){
min -= 10;
std::cout << "min" << min << nextNumber << std::endl;
teque.insert(std::pair<float, int>(min, nextNumber));
}
else if(nextCommand == "push_middle"){
std::map<float, int>::iterator it = teque.find(mid);
if(teque.size() % 2 == 0){
std::cout << "fine1" << std::endl;
mid = (it->first + (it--)->first) / 2;
}
else
{
if(it != teque.begin()){
std::cout << "fine2" << std::endl;
mid = (it->first + (it++)->first) / 2;
}
else
{
std::cout << "fine3" << std::endl;
mid = it->first / 2;
}
}
std::cout << "mid" << mid << nextNumber << std::endl;
teque.insert(std::pair<float, int>(mid, nextNumber));
}
else if(nextCommand == "get"){
std::cout << teque[nextNumber] << std::endl;
}
}
}