fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <map>
  4. #include <set>
  5. #include <cmath>
  6. #include <vector>
  7. #include <climits>
  8. #include <string>
  9. #include <algorithm>
  10. #include <sstream>
  11. using namespace std;
  12.  
  13. vector<string> split(string haystack, string needle) {
  14. vector<string> result;
  15. int startPos = 0;
  16. int foundPos = haystack.find(needle, startPos);
  17. while (foundPos != string::npos) {
  18. int count = foundPos - startPos;
  19. string token = haystack.substr(startPos, count);
  20. if (!token.empty()) {
  21. result.push_back(token);
  22. }
  23. startPos = foundPos + needle.length();
  24. foundPos = haystack.find(needle, startPos);
  25. }
  26. string token = haystack.substr(startPos, haystack.length() - startPos);
  27. if (!token.empty()) {
  28. result.push_back(token);
  29. }
  30. return result;
  31. }
  32.  
  33. int main() {
  34. ios_base::sync_with_stdio(false);
  35. cin.tie(NULL);
  36. string s;getline(cin, s);
  37.  
  38. vector<string> parts = split(s, " ");
  39.  
  40. map<string, int> mp;
  41. for (int i = 0;i < parts.size();i++) {
  42. mp[parts[i]]++;
  43. }
  44.  
  45. for (auto entry : mp) {
  46. cout << entry.first << " " << entry.second << endl;
  47. }
  48.  
  49. for (auto value : parts) {
  50. if (mp[value] != 0) {
  51. cout << value << " " << mp[value] << endl;
  52. mp[value] = 0;
  53. }
  54. }
  55. return 0;
  56. }
  57.  
  58.  
Success #stdin #stdout 0.01s 5224KB
stdin
Standard input is empty
stdout
Standard output is empty