为什么错了?
原题链接:1.A+B problem2026-02-23 16:53:54
发布于:浙江
我不懂错在哪:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ENABLE_VERBOSE_LOGGING 1
#define ENABLE_TIMING 1
#define ENABLE_THREAD_SAFETY 1
#define USE_MULTITHREADING 0
#define MAX_ITERATIONS 1
#define START_OF_PROGRAM do {
#define END_OF_PROGRAM } while(0)
#define BEGIN_NAMESPACE namespace {
#define END_NAMESPACE }
#define UNUSED(x) ((void)(x))
#define IGNORE_RETURN_VALUE(x) if (x) {}
#define LIKELY(x) (__builtin_expect(!!(x), 1))
#define UNLIKELY(x) (__builtin_expect(!!(x), 0))
#define PROGRAM_NAME "A+B Solver"
#define PROGRAM_VERSION "9.9.9"
#define PROGRAM_AUTHOR "Dr. Overkill"
#define PROGRAM_LICENSE "GPLv3+ with extra verbosity clause"
const char* const kProgramName = PROGRAM_NAME;
const char* const kProgramVersion = PROGRAM_VERSION;
const char* const kProgramAuthor = PROGRAM_AUTHOR;
const char* const kProgramLicense = PROGRAM_LICENSE;
const double kPi = 3.14159265358979323846;
const double kEulerNumber = 2.71828182845904523536;
const double kGoldenRatio = 1.61803398874989484820;
const float kFloatZero = 0.0f;
const int kMagicNumber = 42;
const char kGreetingMessage[] = "Welcome to the most over-engineered A+B solver!\n";
const char kFarewellMessage[] = "Thank you for using our software. Have a nice day!\n";
static bool g_initialized = false;
static std::mutex g_global_mutex;
static int g_log_level = 0;
using Integer = int;
using InputPair = std::pair<Integer, Integer>;
using ResultType = Integer;
using Logger = std::ostream;
using ChronoClock = std::chrono::high_resolution_clock;
using TimePoint = ChronoClock::time_point;
using DurationMs = std::chrono::duration<double, std::milli>;
enum class ErrorCode : int {
SUCCESS = 0,
INVALID_INPUT = 1,
DIVISION_BY_ZERO = 2,
OUT_OF_MEMORY = 3,
UNKNOWN_ERROR = 99
};
enum class AdditionStrategyType : uint8_t {
SIMPLE,
BITWISE,
TEMPLATE_META,
MULTITHREADED,
RECURSIVE,
FUNCTIONAL,
NUM_STRATEGIES
};
struct MathConstants {
static constexpr double PI = 3.141592653589793;
static constexpr double E = 2.718281828459045;
static constexpr double GOLDEN_RATIO = 1.618033988749895;
static constexpr int MAX_INT = std::numeric_limits<int>::max();
static constexpr int MIN_INT = std::numeric_limits<int>::min();
};
enum class Weekday {
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
};
enum class Month {
January, February, March, April, May, June, July, August, September, October, November, December
};
enum class Color {
Red, Green, Blue, Yellow, Cyan, Magenta, Black, White
};
struct Point2D { double x, y; };
struct Point3D { double x, y, z; };
struct LineSegment { Point2D start, end; };
namespace OverkillSoft {
namespace APlusB {
namespace Core {
namespace Arithmetic {
namespace details {
template<typename T>
struct IsInteger : std::false_type {};
template<> struct IsInteger<char> : std::true_type {};
template<> struct IsInteger<signed char> : std::true_type {};
template<> struct IsInteger<unsigned char> : std::true_type {};
template<> struct IsInteger<short> : std::true_type {};
template<> struct IsInteger<unsigned short> : std::true_type {};
template<> struct IsInteger<int> : std::true_type {};
template<> struct IsInteger<unsigned int> : std::true_type {};
template<> struct IsInteger<long> : std::true_type {};
template<> struct IsInteger<unsigned long> : std::true_type {};
template<> struct IsInteger<long long> : std::true_type {};
template<> struct IsInteger<unsigned long long> : std::true_type {};
#ifdef __cpp_char8_t
template<> struct IsInteger<char8_t> : std::true_type {};
#endif
#ifdef __cpp_lib_byte
template<> struct IsInteger<std::byte> : std::true_type {};
#endif
} // namespace details
class AdditionStrategy {
public:
virtual ~AdditionStrategy() = default;
virtual ResultType execute(Integer a, Integer b) const = 0;
virtual std::string name() const = 0;
};
class SimpleAdditionStrategy : public AdditionStrategy {
public:
ResultType execute(Integer a, Integer b) const override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[SimpleAdditionStrategy] Adding " << a << " and " << b << " using operator+." << std::endl;
#endif
return a + b;
}
std::string name() const override { return "SimpleAddition"; }
};
class BitwiseAdditionStrategy : public AdditionStrategy {
public:
ResultType execute(Integer a, Integer b) const override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[BitwiseAdditionStrategy] Adding " << a << " and " << b << " using bitwise operations." << std::endl;
#endif
while (b != 0) {
Integer carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a;
}
std::string name() const override { return "BitwiseAddition"; }
};
class RecursiveAdditionStrategy : public AdditionStrategy {
private:
ResultType add_recursive(Integer a, Integer b) const {
if (b == 0) return a;
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[RecursiveAdditionStrategy] Recursion depth: " << (b > 0 ? b : -b) << std::endl;
#endif
if (b > 0)
return add_recursive(a + 1, b - 1);
else if (b < 0)
return add_recursive(a - 1, b + 1);
return a;
}
public:
ResultType execute(Integer a, Integer b) const override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[RecursiveAdditionStrategy] Starting recursive addition." << std::endl;
#endif
return add_recursive(a, b);
}
std::string name() const override { return "RecursiveAddition"; }
};
class MultithreadedAdditionStrategy : public AdditionStrategy {
private:
mutable std::mutex m_mutex;
mutable ResultType m_result;
mutable bool m_completed;
void thread_func(Integer a, Integer b) const {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[MultithreadedAdditionStrategy] Worker thread started." << std::endl;
#endif
ResultType res = a + b;
{
std::lock_guard<std::mutex> lock(m_mutex);
m_result = res;
m_completed = true;
}
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[MultithreadedAdditionStrategy] Worker thread finished." << std::endl;
#endif
}
public:
MultithreadedAdditionStrategy() : m_result(0), m_completed(false) {}
ResultType execute(Integer a, Integer b) const override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[MultithreadedAdditionStrategy] Creating worker thread." << std::endl;
#endif
m_completed = false;
std::thread worker(&MultithreadedAdditionStrategy::thread_func, this, a, b);
worker.join();
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[MultithreadedAdditionStrategy] Worker thread joined." << std::endl;
#endif
return m_result;
}
std::string name() const override { return "MultithreadedAddition"; }
};
template<int A, int B>
struct TemplateMetaAdder {
static constexpr int value = A + B;
};
class TemplateMetaAdditionStrategy : public AdditionStrategy {
public:
ResultType execute(Integer a, Integer b) const override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[TemplateMetaAdditionStrategy] This strategy only works at compile time. Falling back to simple addition." << std::endl;
#endif
return a + b;
}
std::string name() const override { return "TemplateMetaAddition"; }
};
} // namespace Arithmetic
class Adder {
private:
std::unique_ptr<Arithmetic::AdditionStrategy> m_strategy;
mutable std::mutex m_mutex;
public:
explicit Adder(Arithmetic::AdditionStrategy* strategy) : m_strategy(strategy) {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[Adder] Constructed with strategy: " << (strategy ? strategy->name() : "nullptr") << std::endl;
#endif
if (!m_strategy) {
throw std::invalid_argument("Addition strategy cannot be null");
}
}
Adder(const Adder&) = delete;
Adder(Adder&& other) noexcept : m_strategy(std::move(other.m_strategy)) {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[Adder] Move constructed." << std::endl;
#endif
}
~Adder() {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[Adder] Destructor called." << std::endl;
#endif
}
Adder& operator=(const Adder&) = delete;
Adder& operator=(Adder&& other) noexcept {
if (this != &other) {
m_strategy = std::move(other.m_strategy);
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[Adder] Move assignment." << std::endl;
#endif
}
return *this;
}
ResultType add(Integer a, Integer b) const {
#if ENABLE_THREAD_SAFETY
std::lock_guard<std::mutex> lock(m_mutex);
#endif
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[Adder] Performing addition using strategy: " << m_strategy->name() << std::endl;
#endif
return m_strategy->execute(a, b);
}
void setStrategy(Arithmetic::AdditionStrategy* strategy) {
if (!strategy) {
throw std::invalid_argument("New strategy cannot be null");
}
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[Adder] Changing strategy from "
<< (m_strategy ? m_strategy->name() : "null")
<< " to " << strategy->name() << std::endl;
#endif
m_strategy.reset(strategy);
}
};
namespace Input {
class InputReader {
public:
virtual ~InputReader() = default;
virtual std::string readLine() = 0;
virtual bool isGood() const = 0;
};
class StdinReader : public InputReader {
private:
std::istream& m_inputStream;
public:
explicit StdinReader(std::istream& is = std::cin) : m_inputStream(is) {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[StdinReader] Created, using stream: " << (void*)&m_inputStream << std::endl;
#endif
}
std::string readLine() override {
std::string line;
std::getline(m_inputStream, line);
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[StdinReader] Read line: \"" << line << "\"" << std::endl;
#endif
return line;
}
bool isGood() const override {
return m_inputStream.good();
}
};
class FixedStringReader : public InputReader {
private:
std::string m_fixedLine;
bool m_good;
public:
explicit FixedStringReader(const std::string& line) : m_fixedLine(line), m_good(true) {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[FixedStringReader] Created with fixed line: \"" << line << "\"" << std::endl;
#endif
}
std::string readLine() override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[FixedStringReader] Returning fixed line: \"" << m_fixedLine << "\"" << std::endl;
#endif
m_good = false;
return m_fixedLine;
}
bool isGood() const override {
return m_good;
}
};
class CompositeReader : public InputReader {
private:
std::vector<std::unique_ptr<InputReader>> m_readers;
size_t m_currentIndex = 0;
public:
void addReader(std::unique_ptr<InputReader> reader) {
m_readers.push_back(std::move(reader));
}
std::string readLine() override {
while (m_currentIndex < m_readers.size()) {
if (m_readers[m_currentIndex]->isGood()) {
return m_readers[m_currentIndex]->readLine();
} else {
m_currentIndex++;
}
}
return "";
}
bool isGood() const override {
for (size_t i = m_currentIndex; i < m_readers.size(); ++i) {
if (m_readers[i]->isGood()) return true;
}
return false;
}
};
} // namespace Input
namespace Parsing {
class Parser {
public:
virtual ~Parser() = default;
virtual InputPair parse(const std::string& input) = 0;
};
class WhitespaceParser : public Parser {
private:
std::string trim(const std::string& s) const {
size_t start = s.find_first_not_of(" \t\n\r");
size_t end = s.find_last_not_of(" \t\n\r");
if (start == std::string::npos) return "";
return s.substr(start, end - start + 1);
}
public:
InputPair parse(const std::string& input) override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[WhitespaceParser] Parsing string: \"" << input << "\"" << std::endl;
#endif
std::istringstream iss(input);
Integer a, b;
if (!(iss >> a >> b)) {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[WhitespaceParser] Parsing failed." << std::endl;
#endif
throw std::invalid_argument("Input does not contain two integers");
}
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[WhitespaceParser] Parsed numbers: " << a << " and " << b << std::endl;
#endif
return std::make_pair(a, b);
}
};
template<char Delimiter = ' '>
class DelimitedParser : public Parser {
public:
InputPair parse(const std::string& input) override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[DelimitedParser] Parsing with delimiter '" << Delimiter << "'" << std::endl;
#endif
std::stringstream ss(input);
std::string token;
std::vector<std::string> tokens;
while (std::getline(ss, token, Delimiter)) {
if (!token.empty()) {
tokens.push_back(token);
}
}
if (tokens.size() != 2) {
throw std::invalid_argument("Expected exactly two numbers");
}
Integer a = std::stoi(tokens[0]);
Integer b = std::stoi(tokens[1]);
return std::make_pair(a, b);
}
};
#ifdef __cpp_lib_regex
#include <regex>
class RegexParser : public Parser {
private:
std::regex m_pattern;
public:
RegexParser() : m_pattern(R"(^\s*([+-]?\d+)\s+([+-]?\d+)\s*$)") {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[RegexParser] Constructed with regex pattern." << std::endl;
#endif
}
InputPair parse(const std::string& input) override {
std::smatch match;
if (!std::regex_match(input, match, m_pattern) || match.size() != 3) {
throw std::invalid_argument("Input does not match expected pattern");
}
Integer a = std::stoi(match[1].str());
Integer b = std::stoi(match[2].str());
return std::make_pair(a, b);
}
};
#endif
} // namespace Parsing
namespace Validation {
class Validator {
public:
virtual ~Validator() = default;
virtual bool validate(const InputPair& pair) const = 0;
virtual std::string errorMessage() const = 0;
};
class IntRangeValidator : public Validator {
private:
mutable std::string m_lastError;
public:
bool validate(const InputPair& pair) const override {
Integer a = pair.first;
Integer b = pair.second;
if (a < MathConstants::MIN_INT || a > MathConstants::MAX_INT) {
m_lastError = "First number out of range";
return false;
}
if (b < MathConstants::MIN_INT || b > MathConstants::MAX_INT) {
m_lastError = "Second number out of range";
return false;
}
return true;
}
std::string errorMessage() const override { return m_lastError; }
};
class PositiveNumberValidator : public Validator {
private:
mutable std::string m_lastError;
public:
bool validate(const InputPair& pair) const override {
if (pair.first < 0) {
m_lastError = "First number is negative";
return false;
}
if (pair.second < 0) {
m_lastError = "Second number is negative";
return false;
}
return true;
}
std::string errorMessage() const override { return m_lastError; }
};
class CompositeValidator : public Validator {
private:
std::vector<std::unique_ptr<Validator>> m_validators;
mutable std::string m_lastError;
public:
void addValidator(std::unique_ptr<Validator> validator) {
m_validators.push_back(std::move(validator));
}
bool validate(const InputPair& pair) const override {
for (const auto& v : m_validators) {
if (!v->validate(pair)) {
m_lastError = v->errorMessage();
return false;
}
}
return true;
}
std::string errorMessage() const override { return m_lastError; }
};
} // namespace Validation
namespace Output {
class OutputFormatter {
public:
virtual ~OutputFormatter() = default;
virtual std::string format(ResultType result) const = 0;
};
class SimpleFormatter : public OutputFormatter {
public:
std::string format(ResultType result) const override {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[SimpleFormatter] Formatting result: " << result << std::endl;
#endif
return std::to_string(result);
}
};
class DecoratedFormatter : public OutputFormatter {
private:
std::string m_prefix;
std::string m_suffix;
public:
DecoratedFormatter(const std::string& prefix = "", const std::string& suffix = "")
: m_prefix(prefix), m_suffix(suffix) {
#if ENABLE_VERBOSE_LOGGING
std::cerr << "[DecoratedFormatter] Created with prefix \"" << prefix << "\", suffix \"" << suffix << "\"" << std::endl;
#endif
}
std::string format(ResultType result) const override {
return m_prefix + std::to_string(result) + m_suffix;
}
};
class JsonFormatter : public OutputFormatter {
public:
std::string format(ResultType result) const override {
std::ostringstream oss;
oss << "{ \"result\": " << result << " }";
return oss.str();
}
};
class XmlFormatter : public OutputFormatter {
public:
std::string format(ResultType result) const override {
std::ostringstream oss;
oss << "<result>" << result << "</result>";
return oss.str();
}
};
} // namespace Output
namespace Logging {
enum class LogLevel {
DEBUG,
INFO,
WARNING,
ERROR
};
class Logger {
private:
LogLevel m_threshold;
std::ostream& m_outputStream;
public:
explicit Logger(LogLevel threshold = LogLevel::INFO, std::ostream& os = std::cerr)
: m_threshold(threshold), m_outputStream(os) {}
template<typename... Args>
void log(LogLevel level, const Args&... args) const {
if (level >= m_threshold) {
std::lock_guard<std::mutex> lock(g_global_mutex);
(m_outputStream << ... << args) << std::endl;
}
}
};
static Logger g_logger(LogLevel::DEBUG, std::cerr);
#define LOG_DEBUG(...) g_logger.log(LogLevel::DEBUG, "[DEBUG] ", __VA_ARGS__)
#define LOG_INFO(...) g_logger.log(LogLevel::INFO, "[INFO] ", __VA_ARGS__)
#define LOG_WARNING(...) g_logger.log(LogLevel::WARNING, "[WARNING] ", __VA_ARGS__)
#define LOG_ERROR(...) g_logger.log(LogLevel::ERROR, "[ERROR] ", __VA_ARGS__)
} // namespace Logging
namespace Utility {
void nop() {}
int random_number() {
static std::random_device rd;
static std::mt19937 gen(rd());
static std::uniform_int_distribution<> dis(0, 1000);
return dis(gen);
}
void print_banner() {
std::cerr << R"(
╔═══════════════════════════════════════════════════════════════════╗
║ A+B SOLVER - ULTIMATE EDITION ║
║ (with extra verbosity) ║
╚═══════════════════════════════════════════════════════════════════╝
)" << std::endl;
}
} // namespace Utility
class Application {
private:
std::unique_ptr<Input::InputReader> m_reader;
std::unique_ptr<Parsing::Parser> m_parser;
std::unique_ptr<Validation::Validator> m_validator;
std::unique_ptr<Adder> m_adder;
std::unique_ptr<Output::OutputFormatter> m_formatter;
TimePoint m_startTime;
TimePoint m_endTime;
public:
Application(std::unique_ptr<Input::InputReader> reader,
std::unique_ptr<Parsing::Parser> parser,
std::unique_ptr<Validation::Validator> validator,
std::unique_ptr<Adder> adder,
std::unique_ptr<Output::OutputFormatter> formatter)
: m_reader(std::move(reader))
, m_parser(std::move(parser))
, m_validator(std::move(validator))
, m_adder(std::move(adder))
, m_formatter(std::move(formatter)) {
LOG_INFO("Application constructed with all dependencies.");
}
~Application() {
LOG_INFO("Application destroyed.");
}
int run() {
int dummy1 = 0;
int dummy2 = 0;
double dummy3 = 0.0;
std::string dummy4 = "unused";
bool dummy5 = false;
UNUSED(dummy1); UNUSED(dummy2); UNUSED(dummy3); UNUSED(dummy4); UNUSED(dummy5);
static_assert(MathConstants::PI > 3.0, "PI is not greater than 3?");
static_assert(MathConstants::E > 2.7, "E is too small");
#if ENABLE_TIMING
m_startTime = ChronoClock::now();
#endif
LOG_INFO("Application started.");
LOG_INFO("Reading input...");
std::string inputLine;
try {
inputLine = m_reader->readLine();
} catch (const std::exception& ex) {
LOG_ERROR("Exception while reading input: ", ex.what());
return static_cast<int>(ErrorCode::INVALID_INPUT);
}
LOG_INFO("Parsing input...");
InputPair numbers;
try {
numbers = m_parser->parse(inputLine);
} catch (const std::exception& ex) {
LOG_ERROR("Exception while parsing input: ", ex.what());
return static_cast<int>(ErrorCode::INVALID_INPUT);
}
LOG_INFO("Validating numbers...");
if (!m_validator->validate(numbers)) {
LOG_ERROR("Validation failed: ", m_validator->errorMessage());
return static_cast<int>(ErrorCode::INVALID_INPUT);
}
LOG_INFO("Performing addition...");
ResultType result;
try {
result = m_adder->add(numbers.first, numbers.second);
} catch (const std::exception& ex) {
LOG_ERROR("Exception during addition: ", ex.what());
return static_cast<int>(ErrorCode::UNKNOWN_ERROR);
}
LOG_INFO("Formatting result...");
std::string outputStr = m_formatter->format(result);
#if ENABLE_TIMING
m_endTime = ChronoClock::now();
DurationMs elapsed = m_endTime - m_startTime;
LOG_INFO("Elapsed time: ", elapsed.count(), " ms");
#endif
std::cout << outputStr << std::endl;
LOG_INFO("Application finished successfully.");
return static_cast<int>(ErrorCode::SUCCESS);
}
};
} // namespace Core
} // namespace APlusB
} // namespace OverkillSoft
namespace {
class GlobalInitializer {
public:
GlobalInitializer() {
std::cerr << "[GlobalInitializer] Program started initializing globals." << std::endl;
}
~GlobalInitializer() {
std::cerr << "[GlobalInitializer] Program cleaning up globals." << std::endl;
}
} g_initializer;
struct StaticData {
int value;
StaticData() : value(42) {
std::cerr << "[StaticData] Constructed with value " << value << std::endl;
}
} g_static_data;
int g_dummy_array[1000] = {0};
}
template<int N>
constexpr int sum_upto() {
return N + sum_upto<N-1>();
}
template<> constexpr int sum_upto<0>() { return 0; }
static_assert(sum_upto<5>() == 15, "Compile-time sum works");
template<typename... Ts>
struct TypeList {};
using DummyTypes = TypeList<int, double, char, float, long, short, bool>;
template int sum_upto<10>();
template int sum_upto<20>();
int main(int argc, char* argv[]) {
using namespace OverkillSoft::APlusB::Core;
using namespace OverkillSoft::APlusB::Core::Logging;
Utility::print_banner();
std::cerr << "=================================================================" << std::endl;
std::cerr << kGreetingMessage;
std::cerr << "Program: " << kProgramName << ", Version " << kProgramVersion << std::endl;
std::cerr << "Author: " << kProgramAuthor << std::endl;
std::cerr << "License: " << kProgramLicense << std::endl;
std::cerr << "=================================================================" << std::endl;
if (argc > 1) {
std::cerr << "Command line arguments detected (" << argc-1 << "):" << std::endl;
for (int i = 1; i < argc; ++i) {
std::cerr << " argv[" << i << "] = \"" << argv[i] << "\"" << std::endl;
}
} else {
std::cerr << "No command line arguments provided. Proceeding with default behavior." << std::endl;
}
const char* env_log = std::getenv("LOG_LEVEL");
if (env_log) {
std::cerr << "LOG_LEVEL environment variable set to: " << env_log << std::endl;
}
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(1, 100);
int random_dummy = dis(gen);
std::cerr << "Random dummy number generated: " << random_dummy << " (unused)" << std::endl;
UNUSED(random_dummy);
std::cerr << "Loading";
for (int i = 0; i < 5; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
std::cerr << ".";
}
std::cerr << " done!" << std::endl;
std::unique_ptr<Input::InputReader> reader;
#if 1
reader = std::make_unique<Input::StdinReader>();
#else
reader = std::make_unique<Input::FixedStringReader>("42 42");
#endif
std::unique_ptr<Parsing::Parser> parser;
parser = std::make_unique<Parsing::WhitespaceParser>();
#ifdef __cpp_lib_regex
#endif
std::unique_ptr<Validation::Validator> validator;
auto compositeValidator = std::make_unique<Validation::CompositeValidator>();
compositeValidator->addValidator(std::make_unique<Validation::IntRangeValidator>());
validator = std::move(compositeValidator);
std::uniform_int_distribution<> strat_dis(0, static_cast<int>(AdditionStrategyType::NUM_STRATEGIES)-1);
int strategy_choice = strat_dis(gen);
std::cerr << "Randomly selected addition strategy index: " << strategy_choice << std::endl;
std::unique_ptr<Arithmetic::AdditionStrategy> strategy;
switch (strategy_choice) {
case 0: strategy = std::make_unique<Arithmetic::SimpleAdditionStrategy>(); break;
case 1: strategy = std::make_unique<Arithmetic::BitwiseAdditionStrategy>(); break;
case 2: strategy = std::make_unique<Arithmetic::TemplateMetaAdditionStrategy>(); break;
case 3: strategy = std::make_unique<Arithmetic::MultithreadedAdditionStrategy>(); break;
case 4: strategy = std::make_unique<Arithmetic::RecursiveAdditionStrategy>(); break;
default:
std::cerr << "Invalid strategy index, using simple." << std::endl;
strategy = std::make_unique<Arithmetic::SimpleAdditionStrategy>();
break;
}
auto adder = std::make_unique<Adder>(strategy.release());
std::unique_ptr<Output::OutputFormatter> formatter;
formatter = std::make_unique<Output::SimpleFormatter>();
Application app(std::move(reader), std::move(parser), std::move(validator),
std::move(adder), std::move(formatter));
int exit_code = app.run();
std::cerr << kFarewellMessage;
std::cerr << "Exiting with code " << exit_code << " (0 means success)." << std::endl;
if (false) {
std::cerr << "This should never be printed." << std::endl;
std::vector<int> v(1000000, 0);
std::sort(v.begin(), v.end());
std::cerr << "Sorted vector size: " << v.size() << std::endl;
for (size_t i = 0; i < v.size(); ++i) {
v[i] += i;
}
std::cerr << "Sum of vector: " << std::accumulate(v.begin(), v.end(), 0) << std::endl;
}
return exit_code;
}
全部评论 26
wcnm 你用 AI 在这里装什么呢,你不觉得你很 /bangbangt 吗,建议紫衫,免得到时候有更多人骂你
3天前 来自 北京
6不d
1小时前 来自 浙江
0一眼AI,数组长的要命
43分钟前 来自 江苏
0这就是个傻
逼乐子,不用管
42分钟前 来自 北京
0
不是这帖子下面这么多人说梦话吗,什么头文件没有,还啥不用万能头?梦到啥说啥是吧。
3天前 来自 浙江
5还有说代码长就是错的,何意味
3天前 来自 浙江
1长也没错,但是没按题目标准输出吧...
2天前 来自 海南
1一眼 AI,我的意思是下面一群人屁都不懂就在哪说梦话
2天前 来自 浙江
1
wcnm 你用 AI 在这里装什么呢,你不觉得你很 /bangbangt 吗,建议紫衫,免得到时候有更多人骂你
56分钟前 来自 浙江
4wcnm 你用 AI 在这里装什么呢,你不觉得你很 /bangbangt 吗,建议紫衫,免得到时候有更多人骂你
2小时前 来自 湖北
3不能直接1个万能头吗,这搁哪个编译器不炸
3天前 来自 山东
3说梦话吗
2天前 来自 浙江
0
评论区好多人说梦话,拿AI装啥呢
1小时前 来自 上海
2睡着了都
1小时前 来自 浙江
01
1小时前 来自 上海
0
紫衫
2天前 来自 江苏
2s b
1小时前 来自 浙江
0唐,人家又没说错
56分钟前 来自 浙江
0
52分钟前 来自 浙江
0
头文件都不写,我XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3天前 来自 福建
2第十八个不是吗?
3天前 来自 浙江
1你在说梦话吗
3天前 来自 浙江
0
#include<bits/stdc++.h>呢
3天前 来自 福建
1额
3天前 来自 浙江
1和这个有关系吗?
2天前 来自 浙江
1
你这不炸我吃
3天前 来自 浙江
1d
33分钟前 来自 浙江
0
你这包错的
3天前 来自 浙江
16
2小时前 来自 广东
16
2小时前 来自 广东
16
2小时前 来自 广东
1
D
59分钟前 来自 上海
0文输本入请
1小时前 来自 河北
0觉得自己很能吗
1小时前 来自 江苏
0666这风格AI浓度114514%
1小时前 来自 江苏
0这能上榜我也是服了
1小时前 来自 浙江
0
不是这又是咋上榜的
1小时前 来自 浙江
0被骂的
1小时前 来自 浙江
0我不就是靠被骂出名嘛
1小时前 来自 浙江
0这个傻
逼不用管他
43分钟前 来自 北京
1
666
1小时前 来自 广东
0666
1小时前 来自 广东
0666
1小时前 来自 广东
06
2天前 来自 浙江
0























































有帮助,赞一个