Ai
1 Star 1 Fork 0

hangq/coder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
problem.h 4.16 KB
一键复制 编辑 原始数据 按行查看 历史
/*
* Created by hangangqiang on 2020.11.21.
*/
#ifndef LEETCODE_QUESTION_H
#define LEETCODE_QUESTION_H
#include <functional>
#include <memory>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "data.h"
#include "solution.h"
#include "test_case.h"
#include "tool_proxy/check_result_proxy.h"
#include "tool_proxy/check_codeforces_result_proxy.h"
#include "tool_proxy/count_time_proxy.h"
#include "tool_proxy/rd_inout_proxy.h"
enum ProblemType { kLeetCode = 0, kCodeForces = 1, kHuawei = 2, kOthers = 3 };
class Problem {
public:
Problem(ProblemType type, std::string problem_id, std::string name, std::string desc = "")
: problem_type_(type), problem_id_(std::move(problem_id)), name_(std::move(name)), desc_(std::move(desc)){};
virtual ~Problem() { test_cases_.clear(); }
void SetProblemId(const std::string &id) { this->problem_id_ = id; }
std::string GetProblemId() const { return this->problem_id_; }
void SetName(const std::string &name) { this->name_ = name; }
std::string GetName() const { return this->name_; }
void SetDesc(const std::string &desc) { this->desc_ = desc; }
std::string GetDesc() const { return this->desc_; }
Problem &AddTestCase(std::unique_ptr<TestCase> test_cast) {
if (test_cast->GetName().empty()) {
test_cast->SetName(std::to_string(test_case_count_));
}
test_case_count_++;
this->test_cases_.emplace_back(std::move(test_cast));
return *this;
}
Problem &AddSolution(std::unique_ptr<Solution> solution) {
if (solution->GetName().empty()) {
solution->SetName(std::to_string(solution_count_));
}
solution_count_++;
solution = std::make_unique<CountTimeProxy>(std::move(solution));
if (problem_type_ == ProblemType::kCodeForces) {
solution = std::make_unique<RDInOutProxy>(std::move(solution));
solution = std::make_unique<CheckCFResultProxy>(std::move(solution));
} else {
solution = std::make_unique<CheckResultProxy>(std::move(solution));
}
this->solutions_.emplace_back(std::move(solution));
return *this;
}
virtual void Execute();
protected:
ProblemType problem_type_;
std::string problem_id_;
std::string name_;
std::string desc_;
size_t test_case_count_{0};
std::vector<std::unique_ptr<TestCase>> test_cases_{};
size_t solution_count_{0};
std::vector<std::unique_ptr<Solution>> solutions_{};
};
#define DefProblem(type, id) \
class QA##type##id : public Question { \
public: \
explicit QA##type##id(std::string name, std::string desc = "") \
: Question(type, #id, std::move(name), std::move(desc)){}; \
}
#define DefLeetCodeProblem(id) \
class QALeetCode##id : public Problem { \
public: \
explicit QALeetCode##id(std::string name, std::string desc = "") \
: Problem(kLeetCode, #id, std::move(name), std::move(desc)){}; \
}
#define DefCodeForcesProblem(id) \
class QACodeForces##id : public Problem { \
public: \
explicit QACodeForces##id(std::string name, std::string desc = "") \
: Problem(kCodeForces, #id, std::move(name), std::move(desc)){}; \
}
#define DefHuaweiProblem(id) \
class QAHuawei##id : public Problem { \
public: \
explicit QAHuawei##id(std::string name, std::string desc = "") \
: Problem(kHuawei, #id, std::move(name), std::move(desc)){}; \
}
#define DefOthersProblem(id) \
class QAOthers##id : public Problem { \
public: \
explicit QAOthers##id(std::string name, std::string desc = "") \
: Problem(kOthers, #id, std::move(name), std::move(desc)){}; \
}
#endif // LEETCODE_QUESTION_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hangangqiang/coder.git
git@gitee.com:hangangqiang/coder.git
hangangqiang
coder
coder
master

搜索帮助