-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.cpp
31 lines (29 loc) · 1.12 KB
/
main.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
#include <iostream>
#include <sstream>
#include <vector>
#include <fn.hpp> // https://raw.githubusercontent.com/senapk/cppaux/master/fn.hpp
using namespace fn;
int main() {
std::vector<int> vet;
while (true) {
auto line = input();
write("$" + line);
auto args = split(line);
if (args[0] == "end") { break; }
else if (args[0] == "push") {
for (size_t i = 1; i < args.size(); ++i) {
vet.push_back((int) number(args[i]));
}
}
else if (args[0] == "show") { write("[" + join(vet, ", ") + "]"); }
else if (args[0] == "erase") { vet.erase(vet.begin() + (int) number(args[1])); }
else if (args[0] == "media") {
double sum = 0;
for (auto item : vet) {
sum += item;
}
write(format("{%.2f}", sum / vet.size()));
}
else { write("fail: invalid command"); }
}
}