Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lora'sFanClub.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <unordered_map>
- #include <string>
- #include <sstream>
- #include <algorithm>
- std::unordered_map<std::string, std::unordered_map<std::string, int>> boys;
- void removePossitiveValues(const std::string& name) {
- for (auto iter = boys.begin(); iter != boys.end(); iter++) {
- if (iter->first == name) {
- for (auto it = iter->second.begin(); it != iter->second.end(); it++) {
- if (it->second >= 0) {
- boys[iter->first][it->first] = 0;
- }
- }
- }
- }
- }
- int getTratiValue(const std::string& trait, int value) {
- if (trait == "Greedy" || trait == "Rude" || trait == "Dumb") {
- return value * -1;
- }
- else if (trait == "Kind") {
- return value * 2;
- }
- else if (trait == "Handsome") {
- return value * 3;
- }
- else if (trait == "Smart") {
- return value * 5;
- }
- else {
- return value;
- }
- }
- void setBoys(const std::string& name, const std::string& trait, int value) {
- for (auto iter = boys.begin(); iter != boys.end(); iter++) {
- if (iter->first == name) {
- for (auto it = iter->second.begin(); it != iter->second.end(); it++) {
- if (it->first == trait) {
- if (it->second < value) {
- boys[iter->first][it->first] = value;
- return;
- }
- }
- }
- }
- }
- boys[name][trait] = value;
- }
- auto cmpBySum = [&](const std::pair<int, std::string>& a, const std::pair<int, std::string>& b)
- {
- return a.first != b.first ? a.first > b.first : a.second < b.second;
- };
- auto compByKey = [&](const std::pair<int, std::string>& a, const std::pair<int, std::string>& b) {
- return a.first > b.first;
- };
- int main() {
- std::string input;
- getline(std::cin, input);
- while (input != "Make a decision already!") {
- std::istringstream arguments(input);
- std::string name, trait, value;
- int number;
- arguments >> name >> trait >> value;
- if (value == "Gyubek!") {
- removePossitiveValues(name);
- }
- else {
- std::istringstream numInput(value);
- numInput >> number;
- int traitValue = getTratiValue(trait, number);
- setBoys(name, trait, traitValue);
- }
- getline(std::cin, input);
- }
- std::vector<std::pair<int, std::string>> sortedBySum;
- for (auto iter = boys.begin(); iter != boys.end(); iter++) {
- int sum = 0;
- std::pair<int, std::string> current;
- for (auto it = iter->second.begin(); it != iter->second.end(); it++) {
- sum += it->second;
- }
- current = { sum, iter->first };
- sortedBySum.push_back(current);
- }
- std::sort(sortedBySum.begin(), sortedBySum.end(), cmpBySum);
- for (auto p : sortedBySum) {
- std::cout << "# "<< p.second << ": " << p.first << std::endl;
- std::vector<std::pair<int, std::string>> sortedByValue;
- for (auto e : boys[p.second]) {
- sortedByValue.push_back(std::pair<int, std::string>{e.second, e.first});
- }
- std::sort(sortedByValue.begin(), sortedByValue.end(), compByKey);
- for (auto x : sortedByValue) {
- if (x.first != 0)
- {
- std::cout << "!!! " << x.second << " -> " << x.first << std::endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment