-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstream.cpp
More file actions
35 lines (31 loc) · 699 Bytes
/
Copy pathstream.cpp
File metadata and controls
35 lines (31 loc) · 699 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
33
34
35
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <cstring>
void E(std::istream& input) {
int running = 0, above = 0;
double line;
std::unordered_map<int, int> H(150);
while(input >> line) {
int ride = static_cast<int>(line);
if (ride > running) {
H[ride]++;
if (++above > running) {
running++;
above -= H[running];
H.erase(running);
}
}
std::cout << running << std::endl;
}
}
int main(int argc, char *argv[]) {
if (argc == 1 || !strcmp(argv[1], "-")) {
E(std::cin);
} else {
std::ifstream file(argv[1]);
std::istream& file_stream = file;
E(file_stream);
}
return EXIT_SUCCESS;
}