diff --git a/onlinejudge_template/generator/_topcoder.py b/onlinejudge_template/generator/topcoder.py similarity index 77% rename from onlinejudge_template/generator/_topcoder.py rename to onlinejudge_template/generator/topcoder.py index 8680fc2..b403552 100644 --- a/onlinejudge_template/generator/_topcoder.py +++ b/onlinejudge_template/generator/topcoder.py @@ -3,6 +3,11 @@ from onlinejudge_template.generator._utils import get_analyzed +def is_topcoder(data: Dict[str, Any]) -> bool: + definition = get_analyzed(data).topcoder_class_definition + return definition is not None + + def class_name(data: Dict[str, Any]) -> str: definition = get_analyzed(data).topcoder_class_definition if definition is None: diff --git a/onlinejudge_template_resources/template/main.cpp b/onlinejudge_template_resources/template/main.cpp index f77c919..dc39611 100644 --- a/onlinejudge_template_resources/template/main.cpp +++ b/onlinejudge_template_resources/template/main.cpp @@ -3,6 +3,7 @@ import platform import onlinejudge_template.generator.cplusplus as cplusplus + import onlinejudge_template.generator.topcoder as topcoder import onlinejudge_template.generator.about as about %>\ <% @@ -27,9 +28,20 @@ using namespace std; ${cplusplus.declare_constants(data)} +% if topcoder.is_topcoder(data): +<% solve_function = topcoder.class_name(data) + "()." + topcoder.method_name(data) %>\ +class ${topcoder.class_name(data)} { +public: + ${cplusplus.return_type(data)} ${topcoder.method_name(data)}(${cplusplus.formal_arguments(data)}) { + // TODO: edit here + } +}; +% else: +<% solve_function = "solve" %>\ ${cplusplus.return_type(data)} solve(${cplusplus.formal_arguments(data)}) { // TODO: edit here } +% endif // generated by ${about.title} ${about.version} (${about.url}) int main() { @@ -37,7 +49,7 @@ int main() { std::cin.tie(nullptr); constexpr char endl = '\n'; ${cplusplus.read_input(data)} - auto ${cplusplus.return_value(data)} = solve(${cplusplus.actual_arguments(data)}); + auto ${cplusplus.return_value(data)} = ${solve_function}(${cplusplus.actual_arguments(data)}); ${cplusplus.write_output(data)} return 0; } diff --git a/onlinejudge_template_resources/template/topcoder.cpp b/onlinejudge_template_resources/template/topcoder.cpp deleted file mode 100644 index c60d5c3..0000000 --- a/onlinejudge_template_resources/template/topcoder.cpp +++ /dev/null @@ -1,45 +0,0 @@ -<%! - import os - import platform - - import onlinejudge_template.generator.cplusplus as cplusplus - import onlinejudge_template.generator._topcoder as _topcoder - import onlinejudge_template.generator.about as about -%>\ -<% - data['config']['rep_macro'] = 'REP' - data['config']['using_namespace_std'] = True - data['config']['long_long_int'] = 'int64_t' - if platform.system() == 'Linux' and "clang" not in os.environ.get("CXX", "g++"): - include = "#include " - else: - include = "\n".join([ - "#include ", - "#include ", - "#include ", - ]) -%>\ -${include} -#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) -#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) -#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) -#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) -#define ALL(x) ::std::begin(x), ::std::end(x) -using namespace std; - -${cplusplus.declare_constants(data)} -class ${_topcoder.class_name(data)} { -public: - ${cplusplus.return_type(data)} ${_topcoder.method_name(data)}(${cplusplus.formal_arguments(data)}) { - } -}; - -#ifdef LOCAL -// generated by ${about.title} ${about.version} (${about.url}) -int main() { -${cplusplus.read_input(data)} - auto ${cplusplus.return_value(data)} = ${_topcoder.class_name(data)}().${_topcoder.method_name(data)}(${cplusplus.actual_arguments(data)}); -${cplusplus.write_output(data)} - return 0; -} -#endif