Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- bool is_find(vector<string>& v, string el) {
- return find(v.begin(), v.end(), el) != v.end();
- }
- vector<string> string_split(string& str) {
- vector<string> v;
- string el = "";
- for (size_t i = 0; i < str.size(); i++) {
- if (str[i] == ' ') {
- if (!el.empty()) {
- if (v.empty()) {
- v.push_back(el);
- v.push_back("");
- }
- else {
- v[1] += el + " ";
- }
- el = "";
- }
- }
- else {
- el += str[i];
- }
- }
- v[1] += el;
- return v;
- }
- void print_join(vector<string>& v, string sep) {
- if (v.empty()) {
- cout << "<empty>\n";
- }
- else {
- for (size_t i = 0; i < v.size() - 1; i++) {
- cout << v[i] << sep;
- }
- cout << v.back() << endl;
- }
- }
- int main() {
- map<int, vector<string>> fishBags;
- map<string, int> fishCount;
- string command;
- getline(cin, command);
- while (command != "END") {
- vector<string> tokens = string_split(command);
- int n = stoi(tokens[0]);
- string fish = tokens[1];
- if (fish == "THROW") {
- if (!fishBags[n].empty()) {
- fish = fishBags[n].back();
- fishCount[fish]--;
- if (fishCount[fish] == 0) {
- fishCount.erase(fish);
- }
- fishBags[n].pop_back();
- }
- }
- else {
- fishBags[n].push_back(fish);
- fishCount[fish]++;
- }
- getline(cin, command);
- }
- for (auto& b : fishBags) {
- cout << b.first << ": ";
- print_join(b.second, ", ");
- }
- vector<string> restaurantFish;
- getline(cin, command);
- while (command != "END") {
- if (fishCount.find(command) != fishCount.end()) {
- restaurantFish.push_back(command);
- }
- getline(cin, command);
- }
- cout << "Restaurant: ";
- if (restaurantFish.empty()) {
- cout << "<nothing>\n";
- }
- else {
- for (auto& f : restaurantFish) {
- cout << f << ": " << fishCount[f];
- fishCount.erase(f.c_str());
- if (f != restaurantFish.back()) {
- cout << ", ";
- }
- }
- cout << endl;
- }
- cout << "Pate: ";
- if (fishCount.empty()) {
- cout << "<nothing>\n";
- }
- else {
- for (auto& f : fishCount) {
- cout << f.first << ": " << f.second;
- if (f.first != fishCount.rbegin()->first) {
- cout << ", ";
- }
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement