Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cmath>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <iterator>
- #define int long long
- using namespace std;
- signed main() {
- int n, m, k;
- cin >> n >> m >> k;
- vector<set<int>> v(m);
- for (int i = 0; i < k; i++) {
- string command;
- cin >> command;
- if (command == "ADD") {
- int e, s;
- cin >> e >> s;
- v[s].insert(e);
- continue;
- }
- if (command == "DELETE") {
- int e, s;
- cin >> e >> s;
- v[s].erase(v[s].find(e));
- continue;
- }
- if (command == "CLEAR") {
- int s;
- cin >> s;
- v[s].clear();
- continue;
- }
- if (command == "LISTSET") {
- int s;
- cin >> s;
- bool is_exist = false;
- set<int>::iterator it = v[s].begin();
- for (; it != v[s].end(); it++) {
- is_exist = true;
- cout << *it << " ";
- }
- if (is_exist == false) {
- cout << -1 << '\n';
- }
- else {
- cout << '\n';
- }
- continue;
- }
- if (command == "LISTSETSOF") {
- int e;
- cin >> e;
- bool is_exist = false;
- for (int i = 0; i < m; i++) {
- if (v[i].find(e) != v[i].end()) {
- is_exist = true;
- cout << i << " ";
- }
- }
- if (is_exist == false) {
- cout << -1 << '\n';
- }
- else {
- cout << '\n';
- }
- }
- }
- }
- или
- #include <algorithm>
- #include <cmath>
- #include <iostream>
- #include <iterator>
- #include <map>
- #include <set>
- #include <string>
- #include <vector>
- #define int long long
- using namespace std;
- signed main()
- {
- int n, m, k;
- cin >> n >> m >> k;
- vector<set<int>> v(m);
- for (int i = 0; i < k; i++) {
- string command;
- cin >> command;
- if (command == "ADD") {
- int e, s;
- cin >> e >> s;
- v[s].insert(e);
- continue;
- }
- if (command == "DELETE") {
- int e, s;
- cin >> e >> s;
- v[s].erase(v[s].find(e));
- continue;
- }
- if (command == "CLEAR") {
- int s;
- cin >> s;
- v[s].clear();
- continue;
- }
- if (command == "LISTSET") {
- int s;
- cin >> s;
- bool is_exist = false;
- set<int>::iterator it = v[s].begin();
- for (; it != v[s].end(); it++) {
- is_exist = true;
- cout << *it << " ";
- }
- if (is_exist == false) {
- cout << -1 << '\n';
- } else {
- cout << '\n';
- }
- continue;
- }
- if (command == "LISTSETSOF") {
- int e;
- cin >> e;
- bool is_exist = false;
- for (int i = 0; i < m; i++) {
- if (v[i].find(e) != v[i].end()) {
- is_exist = true;
- cout << i << " ";
- }
- }
- if (is_exist == false) {
- cout << -1 << '\n';
- } else {
- cout << '\n';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement