#include #include #include #include #include #include #include int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return 1; } std::cout << std::fixed << std::setprecision(5); std::vector vector; try { if (argc == 2) { std::string input = argv[1]; std::istringstream inputStream(input); std::string string; while (inputStream >> string) { for (size_t i = 0; i < string.size(); ++i) if (!std::isdigit(static_cast(string[i]))) throw std::runtime_error("Error: not a number"); long number = std::strtol(string.c_str(), NULL, 10); if (number < 0) throw std::runtime_error("Error: negative number"); if (number > std::numeric_limits::max()) throw std::runtime_error("Error: too large"); vector.push_back(static_cast(number)); } } else { for (int i = 1; i < argc; ++i) { for (size_t j = 0; argv[i][j] != '\0'; ++j) if (!std::isdigit(static_cast(argv[i][j]))) throw std::runtime_error("Error: not a number"); long int number = std::strtol(argv[i], NULL, 10); if (number < 0) throw std::runtime_error("Error: negative number"); if (number > std::numeric_limits::max()) throw std::runtime_error("Error: too large"); vector.push_back(static_cast(number)); } } } catch (const std::exception& exception) { std::cerr << exception.what() << std::endl; return EXIT_FAILURE; } std::deque deque(vector.begin(), vector.end()); PmergeMe::sort(vector, deque); }