Giter VIP home page Giter VIP logo

Comments (5)

bytemain avatar bytemain commented on September 7, 2024

应该要拆成三个函数,

judge/run/check

然后在里面 init config

from code-runner.

bytemain avatar bytemain commented on September 7, 2024
struct Result *judge(int argc, char *argv[])
{
}

struct Result *run(int argc, char *argv[])
{
}

int check(int argc, char *argv[])
{
}

from code-runner.

bytemain avatar bytemain commented on September 7, 2024

f303c29

from code-runner.

bytemain avatar bytemain commented on September 7, 2024
from ctypes import *

libjudge = cdll.LoadLibrary("./libjudge.so")

# 自定义基类结构体
class myStructure(Structure):
    # 结构体转字典
    def dump_dict(self):
        info = {}
        # 通过_fields_获取每一个字段
        # 检查每个字段的类型,根据不同类型分别处理
        # 支持递归迭代
        for k, v in self._fields_:
            av = getattr(self, k)
            if type(v) == type(Structure):
                av = av.dump_dict()
            elif type(v) == type(Array):
                av = cast(av, c_char_p).value.decode()
            else:
                pass
            info[k] = av
        return info

    # 字符串转换
    def __str__(self):
        info = self.dump_dict()
        return repr(info)

    # 打印信息
    def show(self):
        from pprint import pprint

        pprint(self.dump_dict())


class Result(myStructure):
    _field = [
        ("status", c_int),
        ("cpu_time_used", c_int),
        ("cpu_time_used_us", c_long),
        ("real_time_used", c_int),
        ("real_time_used_us", c_long),
        ("memory_used", c_int),
        ("signal", c_int),
        ("exit_code", c_int),
    ]


class Config(myStructure):
    _fields_ = [
        ("run_mode", c_int),
        ("check_mode", c_int),
        ("judge_mode", c_int),
        ("cmd", POINTER(c_char_p)),
        ("log_file", c_char_p),
        ("time_limit", c_int),
        ("memory_limit", c_int),
        ("in_file", c_char_p),
        ("out_file", c_char_p),
        ("user_out_file", c_char_p),
    ]


judge = libjudge.judge
judge.restype = None
judge.argtypes = [POINTER(Config)]
cmd = (c_char_p * 2)(b"./main", b"1234234")

config = Config(
    judge_mode=1,
    cmd=pointer(cmd),
    log_file=b"1.log",
    time_limit=1000,
    memory_limit=2048,
    in_file=b"./tests/1/1.in",
    out_file=b"./tests/1/1.out",
    user_out_file=b"1.tmp.out",
)
config.show()
judge(byref(config))

from code-runner.

bytemain avatar bytemain commented on September 7, 2024
void judge(struct Config *config)
{
  printf("run_mode %d\n", config->run_mode);
  printf("check_mode %d\n", config->check_mode);
  printf("judge_mode %d\n", config->judge_mode);
  printf("cmd %s\n", *config->cmd);
  printf("log_file %s\n", config->log_file);
  printf("time_limit %d\n", config->time_limit);
  printf("memory_limit %d\n", config->memory_limit);
  printf("in_file %s\n", config->in_file);
  printf("out_file %s\n", config->out_file);
  printf("user_out_file %s\n", config->user_out_file);
  printf("log_file %s\n", config->log_file);
}

from code-runner.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.