fork(1) download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. struct Pair{
  10. string name;
  11. double val;
  12. };
  13.  
  14. vector<Pair> pairs;
  15.  
  16. double& value(const string& s)
  17. {
  18. for(int i=0; i < pairs.size(); i++)
  19. if(s == pairs[i].name)
  20. return pairs[i].val;
  21.  
  22. Pair p = {s, 0};
  23. pairs.push_back(p);
  24.  
  25. return pairs[pairs.size() - 1].val;
  26. }
  27.  
  28. int main()
  29. {
  30. string buf;
  31. while(cin>>buf) value(buf)++;
  32.  
  33. for(vector<Pair>::const_iterator p = pairs.begin(); p != pairs.end(); ++p)
  34. cout << p->name << ": " << p->val << '\n';
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.02s 2684KB
stdin
Standard input is empty
stdout
Standard output is empty