int main() { int numChefs, numMails; char buff[11], buff2[11]; scanf("%d%d", &numChefs, &numMails); std::string chefName, countryName; while(numChefs--) { //std::cin >> chefName; //std::cin >> countryName; scanf("%s%s", buff, buff2); chefName = buff; countryName = buff2; chef2Country[chefName] = countryName; country2Count[countryName] = 0; chef2Count[chefName] = 0; } while(numMails--) { //std::cin >> chefName; scanf("%s", buff); chefName = buff; chef2Count[chefName]++; country2Count[chef2Country[chefName]]++; } int maxCount = -1; std::string maxCountChef; for(Str2Int::iterator x= chef2Count.begin(); x != chef2Count.end(); x++) { if(x->second > maxCount) { maxCount = x->second; maxCountChef = x->first; } } maxCount = -1; std::string maxCountCountry; for(Str2Int::iterator x= country2Count.begin(); x != country2Count.end(); x++) { if(x->second > maxCount) { maxCount = x->second; maxCountCountry = x->first; } } //Str2Int:: iterator maxChef = std::max_element(chef2Count.begin(), chef2Count.end()); //Str2Int::iterator maxCountry = std::max_element(country2Count.begin(), country2Count.end()); //std::cout << maxCountCountry.c_str() << "\n"; //std::cout << maxCountChef.c_str() << "\n"; printf("%s\n%s\n", maxCountCountry.c_str(), maxCountChef.c_str()); return 0; }
void append(const std::string& word) { std::string lower; cybozu::ToLower(lower, word); Str2Int::const_iterator i = word2id_.find(lower); if (i == word2id_.end()) return; const int id = i->second; if (curTf_ == 0) { tf_.push_back(Int2Int()); curTf_ = &tf_.back(); } (*curTf_)[id]++; if (set_.insert(lower).second) { df_[id]++; } }
void put() const { printf("docNum=%d\n", (int)tf_.size()); for (size_t i = 0, n = tf_.size(); i < n; i++) { printf("%d ", (int)i); tf_[i].put(); } puts("word:idx"); word2id_.put(); }
void append(const std::string& word) { std::string lower; cybozu::ToLower(lower, word); std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(lower, (int)id2word_.size())); //printf("word=%s, id=%d, ret=%d\n", ret.first->first.c_str(), ret.first->second, ret.second); if (ret.second) { id2word_.push_back(lower); df_.resize(id2word_.size()); } if (set_.insert(word).second) { df_[ret.first->second]++; } }
bool loadKeywordFile(const std::string& keyFile) { std::ifstream ifs(keyFile.c_str(), std::ios::binary); if (!ifs) return false; std::string word; while (std::getline(ifs, word)) { size_t pos = word.find('\t'); if (pos == std::string::npos) break; word.resize(pos); std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(word, (int)id2word_.size())); if (ret.second) { id2word_.push_back(word); } else { fprintf(stderr, "ERR already set %s\n", word.c_str()); } } df_.resize(id2word_.size()); fprintf(stderr, "#word = %d\n", (int)df_.size()); return true; }