fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <stdexcept>
  5. #include <algorithm>
  6. std::vector<std::string> split(const std::string &str, char delim) {
  7. std::vector<std::string> res;
  8. size_t current = 0, found;
  9. while (std::string::npos != (found = str.find_first_of(delim, current))) {
  10. res.push_back(std::string(str, current, found - current));
  11. current = found + 1;
  12. }
  13. res.push_back(std::string(str, current, str.size() - current));
  14. return res;
  15. }
  16. std::pair<std::string, int> convert_from_input(const std::string & line) {
  17. const auto vec = split(line, ' ');
  18. if (2 != vec.size()) throw std::runtime_error("unknown input");;
  19. std::pair<std::string, int> re(vec.at(0), std::stoi(vec.at(1)));
  20. return re;
  21. }
  22. int main() {
  23. std::vector<std::pair<std::string, int>> shouhin;
  24. std::string buf;
  25. //input
  26. for (std::size_t i = 0; getline(std::cin, buf); i++) {
  27. try {
  28. shouhin.push_back(convert_from_input(buf));
  29. }
  30. catch (std::exception er) {
  31. std::cerr << er.what() << std::endl;
  32. }
  33. }
  34. //swap data
  35. std::reverse(shouhin.begin(), shouhin.end());
  36.  
  37. //print data
  38. for (auto& i : shouhin) {//Range-base for(C++11)
  39. std::cout << i.first << " " << i.second << std::endl;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0s 3284KB
stdin
KQW12 1200
SJH74 2600
IOA9J 3512
stdout
IOA9J 3512
SJH74 2600
KQW12 1200