Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- #include "bits/stdc++.h"
- using namespace std;
- class Word {
- public:
- Word(int cnt, string word) : cnt(cnt), word(std::move(word)) {}
- string word;
- int cnt;
- };
- int compareInt(int x, int y) {
- if (x == y) { return 0; }
- if (x > y) { return 1; }
- return -1;
- }
- bool predicate(Word word1, Word word2) {
- int key = compareInt(word1.cnt, word2.cnt);
- if (key == 0) {
- key = word2.word.compare(word1.word);
- }
- return key >= 0;
- }
- int main() {
- int n;
- cin >> n;
- cin.ignore();
- while (n) {
- map<string, pair<int, unordered_set<string>>> map;
- set<string> people;
- string word;
- string name;
- bool isFirst = true;
- for (int i = 0; i < n; i++) {
- string line;
- getline(cin, line);
- stringstream ss(line);
- while (ss >> word) {
- if (isFirst) {
- name = word;
- isFirst = false;
- people.insert(name);
- } else {
- if (!map.count(word)) {
- pair<int, unordered_set<string>> pair;
- pair.first = 1;
- pair.second.insert(name);
- map.insert(std::pair<string, std::pair<int, unordered_set<string>>>(word, pair));
- } else {
- map.operator[](word).first++;
- map.operator[](word).second.insert(name);
- }
- }
- }
- isFirst = true;
- }
- vector<Word> results;
- for (const auto &x : map) {
- if (x.second.second.size() == people.size()) {
- results.emplace_back(x.second.first, x.first);
- }
- }
- if(results.empty()){
- cout << "ALL CLEAR" << endl;
- } else {
- sort(results.begin(), results.end(), predicate);
- for (const auto &x : results) {
- cout << x.word << endl;
- }
- }
- cin >> n;
- cin.ignore();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement