Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include "arrays.h"
- void task1(int& l, vector <vector<string>>& v);
- void task2(int& l, vector <vector<string>>& v);
- using namespace std;
- int main()
- {
- /*int n, m;
- cout << "Enter n, m:" << endl;
- cin >> n;
- cin >> m;
- vector<string> A(n);
- vector<string> B(m);
- vector<string> C(0);
- cout << "Enter A: " << endl;
- cin.ignore(100, '\n');
- cin.clear();
- for (int i = 0; i < n; i++)
- {
- getline(cin, A[i]);
- }
- cout << "Enter B: " << endl;
- for (int i = 0; i < m; i++)
- {
- getline(cin, B[i]);
- }
- arrays::Union(A, B, C);
- for (int i = 0; i < C.size(); i++)
- {
- std::cout << C[i] << " ";
- }
- std::cout << std::endl;
- C.clear();
- arrays::Intersection(A, B, C);
- for (int i = 0; i < C.size(); i++)
- {
- std::cout << C[i] << " ";
- }
- C.clear();
- std::cout << std::endl;
- arrays::Difference(A, B, C);
- for (int i = 0; i < C.size(); i++)
- {
- std::cout << C[i] << " ";
- }
- std::cout << std::endl;
- arrays::Affiliation("4", A);*/
- int l;
- int count = 0;
- cout << "Enter l:" << endl;
- cin >> l;
- cin.ignore(100, '\n');
- cin.clear();
- string str;
- vector <vector<string>> v(l);
- for (int i = 0; i < l; i++)
- {
- cout << "Enter " << i + 1 << " vector:" << endl;
- getline(cin, str);
- while (str != "vika")
- {
- //getline(cin, str);
- //v[i].push_back(str);
- //str.clear();
- v[i].push_back(str);
- getline(cin, str);
- count++;
- }
- str.clear();
- count = 0;//потом проверить и убрать
- }
- //---------------------------
- //№1
- vector<string> C(0);
- for (int i = 0; i < l-1; i++)
- {
- arrays::Intersection(v[i], v[i+1], C);
- v[i + 1].clear();
- for (int j = 0; j < C.size(); j++)
- {
- v[i + 1].push_back(C[j]);
- }
- C.clear();
- }
- vector<string> rez1;
- rez1.clear();
- for (int j = 0; j < v[l-1].size(); j++)
- {
- rez1.push_back(v[l-1][j]);
- }
- for (int j = 0; j < rez1.size(); j++)
- {
- cout << rez1[j] << " ";
- }
- cout << endl;
- //------------------------------
- //#2
- bool affiliation;
- for (int i = 1; i < l; i++)
- {
- for (int j = 0; j < v[0].size(); j++)
- {
- if (arrays::Affiliation(v[0][j], v[i]))
- {
- if ((i == l - 1)&&(j==v[0].size()-1))
- {
- affiliation = 1;
- }
- continue;
- }
- else
- {
- affiliation = 0;
- break;
- }
- }
- }
- if (affiliation)
- {
- cout << "Yes" << endl;
- }
- else
- {
- cout << "No" << endl;
- }
- /*for (int i = 0; i < l; i++)
- {
- for (int j = 0; j < v[i].size(); j++)
- {
- cout << v[i][j] << " ";
- }
- }*/
- return 0;
- }
- #include "arrays.h"
- namespace arrays {
- /*std::vector<std::string> Union(std::vector<std::string> First, std::vector<std::string> Second)
- {
- std::vector<std::string> _union (First.size()+ Second.size());
- for (int i = 0; i < First.size(); i++)
- {
- _union[i] = First[i];
- }
- for (int i = 0; i < Second.size(); i++)
- {
- _union[First.size()+i] = Second[i];
- }
- for (int i = 0; i < First.size(); i++)
- {
- for (int j = First.size(); j < _union.size(); j++)
- {
- if (_union[i] == _union[j])
- {
- _union.erase(_union.begin() + j);
- j--;//
- }
- }
- }
- for (int i = 0; i < _union.size(); i++)
- {
- std::cout << _union[i] << " ";
- }
- std::cout << std::endl;
- return _union;
- }*/
- void Union(std::vector<std::string> First, std::vector<std::string> Second, std::vector<std::string> &_union)
- {
- _union.resize(First.size() + Second.size());
- for (int i = 0; i < First.size(); i++)
- {
- _union[i] = First[i];
- }
- for (int i = 0; i < Second.size(); i++)
- {
- _union[First.size() + i] = Second[i];
- }
- for (int i = 0; i < First.size(); i++)
- {
- for (int j = First.size(); j < _union.size(); j++)
- {
- if (_union[i] == _union[j])
- {
- _union.erase(_union.begin() + j);
- j--;//
- }
- }
- }
- }
- //--------------------------------
- /*std::vector<std::string> Intersection(std::vector<std::string> First, std::vector<std::string> Second)
- {
- std::vector<std::string> _intersection(0);
- for (int i = 0; i < First.size(); i++)
- {
- for (int j = 0; j < Second.size(); j++)
- {
- if (First[i] == Second[j])
- {
- _intersection.push_back(First[i]);
- break;
- }
- }
- }
- for (int i = 0; i < _intersection.size(); i++)
- {
- std::cout << _intersection[i] << " ";
- }
- std::cout << std::endl;
- return _intersection;
- }*/
- void Intersection(std::vector<std::string> First, std::vector<std::string> Second, std::vector<std::string>& _intersection)
- {
- _intersection.resize(0);
- for (int i = 0; i < First.size(); i++)
- {
- for (int j = 0; j < Second.size(); j++)
- {
- if (First[i] == Second[j])
- {
- _intersection.push_back(First[i]);
- break;
- }
- }
- }
- /*for (int i = 0; i < _intersection.size(); i++)
- {
- std::cout << _intersection[i] << " ";
- }
- std::cout << std::endl;*/
- //return _intersection;
- }
- //-------------------------------
- /*std::vector<std::string> Difference(std::vector<std::string> First, std::vector<std::string> Second)
- {
- std::vector<std::string> _difference(0);
- for (int i = 0; i < First.size(); i++)
- {
- for (int j = 0; j < Second.size(); j++)
- {
- if (First[i] == Second[j])
- {
- break;
- }
- else
- {
- if (Second.size()-1==j)
- _difference.push_back(First[i]);
- }
- }
- }
- for (int i = 0; i < _difference.size(); i++)
- {
- std::cout << _difference[i] << " ";
- }
- std::cout << std::endl;
- return _difference;
- }*/
- void Difference(std::vector<std::string> First, std::vector<std::string> Second, std::vector<std::string>& _difference)
- {
- _difference.resize(0);
- for (int i = 0; i < First.size(); i++)
- {
- for (int j = 0; j < Second.size(); j++)
- {
- if (First[i] == Second[j])
- {
- break;
- }
- else
- {
- if (Second.size() - 1 == j)
- _difference.push_back(First[i]);
- }
- }
- }
- //return _difference;
- }
- //----------------------------------
- bool Affiliation(std::string element, std::vector<std::string> First)
- {
- for (int i = 0; i < First.size(); i++)
- {
- if (element == First[i])
- {
- //std::cout << "+";
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement