fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <map>
  5. #include <string>
  6. #include <utility>
  7. #include <limits>
  8. #include <cstdlib>
  9.  
  10.  
  11. int main(int argc, char * argv[]) {
  12. // if (argc != 2) {
  13. // std::cerr << "Invalid argument(s). Filename expected." << std::endl;
  14. // return EXIT_FAILURE;
  15. // }
  16.  
  17. // std::ifstream ifs(argv[1]);
  18. // if (!ifs) {
  19. // std::cerr << "Could not open file '" << argv[1] << "' for reading." << std::endl;
  20. // return EXIT_FAILURE;
  21. // }
  22. std::istream & ifs = std::cin;
  23.  
  24. typedef std::map<std::string, std::vector<int> > map_type;
  25. map_type lifts;
  26.  
  27. while (ifs) {
  28. int maxFloor;
  29. int maxWeight;
  30. std::string name;
  31.  
  32. ifs >> maxFloor>> maxWeight >> name;
  33. ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  34.  
  35. std::vector<int> data;
  36. data.reserve(2);
  37. data.push_back(maxFloor);
  38. data.push_back(maxWeight);
  39.  
  40. lifts.insert(std::make_pair(name, data));
  41. }
  42.  
  43. for (map_type::const_iterator it = lifts.begin(); it != lifts.end(); ++it) {
  44. std::cout << it->second[0] << '\t' << it->second[1] << '\t' << it->first << std::endl;
  45. }
  46. }
Success #stdin #stdout 0.01s 2864KB
stdin
12 900 first
10 600 second
15 700 third
20 1000 fourth
16 800 fifth
stdout
16	800	fifth
12	900	first
20	1000	fourth
10	600	second
15	700	third