Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- int main() {
- ifstream fin;
- string path1("in.txt");
- fin.open(path1);
- map<string, vector<pair<string,string>>> vladkol;
- map<string, pair<int, int>> vozrast;
- string str;
- while (getline(fin, str)) {
- int age;
- string vladel(""), vid(""), klicz(""), ages("");
- int n(0);
- for (int i = 0; i < str.length(); i++) {
- if (str[i] == ',') {
- n++;
- continue;
- }
- switch (n) {
- case 0:
- vladel += str[i];
- break;
- case 1:
- vid += str[i];
- break;
- case 2:
- klicz += str[i];
- break;
- case 3:
- ages += str[i];
- break;
- }
- }
- if (klicz == "")
- klicz = "undefined_by_user";
- age = stoi(ages);
- if (vladkol.find(vladel) != vladkol.end()) {
- pair<string, string> p(vid,klicz);
- vladkol.find(vladel)->second.push_back(p);
- }
- else {
- vector<pair<string,string>> v;
- pair<string, string> p(vid, klicz);
- v.push_back(p);
- vladkol.emplace(vladel, v);
- }
- if (vozrast.find(vid) != vozrast.end()) {
- if (age > vozrast.find(vid)->second.second)
- vozrast.find(vid)->second.second = age;
- else if (age < vozrast.find(vid)->second.first)
- vozrast.find(vid)->second.first = age;
- }
- else {
- pair<int, int> f(age, age);
- vozrast.emplace(vid, f);
- }
- }
- link:
- cout << "Vyberite chto hoticie uznac :" << endl;
- cout << "1) Kolvo raznych vidov u vladilca " << endl;
- cout << "2) Vladelcy i kliczki dlia opred vida " << endl;
- cout << "3) Skolko vidov s opredelennoj kliczkoj " << endl;
- cout << "4) Max i min vozrasty vseh vidov" << endl;
- int h;
- vector<string> st;
- vector<string> st1;
- cin >> h;
- if (h < 0 || h > 4)
- goto link;
- string vid;
- string klicz;
- int kolvo(0);
- bool got(0);
- switch (h) {
- case(1):
- for (auto& it : vladkol) {
- int k = it.second.size();
- int kolvo(0);
- vector<string> st;
- bool flag(0);
- for (int i = 0; i < k; i++) {
- for (int j = 0; j < st.size(); j++) {
- if (it.second[i].first == st[j]) {
- flag = 1;
- break;
- }
- }
- if (flag == 1)
- continue;
- else {
- st.push_back(it.second[i].first);
- kolvo++;
- }
- }
- cout << "U vladelca " << it.first << " " << kolvo << " vid(ov) zyvotnych" << endl;
- }
- break;
- case(2):
- cout << "Vvedite vid : ";
- cin >> vid;
- for (auto& it : vladkol) {
- while (!st.empty())
- {
- st.pop_back();
- }
- int k = it.second.size();
- string klicz;
- bool flag(0);
- for (int i = 0; i < k; i++) {
- for (int j = 0; j < st.size(); j++) {
- if (it.second[i].second == st[j]) {
- flag = 1;
- break;
- }
- }
- if (flag == 1) {
- flag = 0;
- continue;
- }
- else {
- if (it.second[i].first == vid) {
- klicz = it.second[i].second;
- st.push_back(klicz);
- cout << "U vladelca " << it.first << " pitomec po kliczke " << klicz << endl;
- got = 1;
- }
- }
- flag = 0;
- }
- }
- if (got == 0)
- cout << "Takoj kliczki neizvestno " << endl;
- break;
- case(3):
- cout << "Vvedite kliczku : ";
- cin >> klicz;
- for (auto& it : vladkol) {
- int k = it.second.size();
- bool flag(0);
- for (int i = 0; i < k; i++) {
- for (int j = 0; j < st1.size(); j++) {
- if (it.second[i].first == st1[j]) {
- flag = 1;
- break;
- }
- }
- if (flag == 1) {
- flag = 0;
- continue;
- }
- else {
- if (it.second[i].second == klicz) {
- kolvo++;
- st1.push_back(it.second[i].first);
- }
- }
- }
- }
- cout << "Kolvo vidov s kliczkoj " << klicz << " ravno " << kolvo;
- break;
- case(4):
- for (auto& it : vozrast) {
- cout << "Max vozrast dlia " << it.first << " is " << it.second.second << " , min " << it.second.first << endl;
- }
- break;
- }
- fin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement