Last active
November 2, 2017 03:22
-
-
Save BeMg/d30cb6682a5c43bf1f5bebee21861ce2 to your computer and use it in GitHub Desktop.
getCount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| const int MAX_HASH = 100000000; | |
| bool cmp(pair<string, int> a, pair<string, int> b) { | |
| return a.second > b.second; | |
| } | |
| int main() { | |
| unordered_map<string, int> mp; | |
| char tmp[100000]; | |
| while(fgets(tmp, 100000, stdin)!=NULL) { | |
| char* ptr = NULL; | |
| ptr = strtok(tmp, "\n\t "); | |
| while(ptr!=NULL) { | |
| mp[string(ptr)] += 1; | |
| ptr = strtok(NULL, "\n\t "); | |
| } | |
| } | |
| vector<pair<string, int>> v; | |
| for(auto i: mp) { | |
| v.push_back(pair<string, int>(i.first, i.second)); | |
| } | |
| sort(v.begin(), v.end(), cmp); | |
| for(auto i: v) { | |
| printf("%d\t%s\n", i.second, i.first.c_str()); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment