#cms #training #api-bindings #cmsocial #olinfo

cms_tools

A rust crate用于与CMSocial编程竞赛平台交互

1 个不稳定版本

0.1.0 2019年11月9日

#cms中的排名:17

每月下载量:36

MIT许可协议

35KB
737

cms_tools

A rust crate用于与CMSocial编程竞赛平台交互

许可协议

许可下


lib.rs:

示例

  • 打印拥有最多最快解决方案的人的列表
//make a client
let client = Client::new(String::from("Gemmady"));
let task_list = client.get_task_list(0, 1024, "", None, None).unwrap();
let mut hm = std::collections::HashMap::<String, u32>::new();
for i in task_list.tasks {
    let best = client.get_stats(&i.name).unwrap().best;
    if best.len() > 0 {
        let t = hm.entry(best[0].username.clone()).or_insert(0);
        *t += 1;
    }
}
let mut v: Vec<(u32, String)> = hm.iter().map(|x| (*x.1, x.0.clone())).collect();
v.sort();
for i in v.iter().rev() {
    println!("{} {}", i.1, i.0);
}
  • 重新提交所有最快解决方案
let username = String::from("user");
let password = "password";
let mut client = Client::new(username.clone());
client.login(password).unwrap();
let user = client.get_user(&username).unwrap();
for sc in user.scores.unwrap() {
    if sc.score == 100.0 {
        println!("{} has score 100", sc.title);
        let sub_list = client.get_submission_list(&sc.name).unwrap();
        let best_sub = sub_list.get_fastest_high(&client).unwrap();
        let files = &best_sub.files;
        if files.len() == 1 { // if it is not an output-only
            let mut submitted: bool = false;
            print!("Resubmitting {}", sc.name.clone());
            while !submitted { // because cmsocial has a limit to submission rate
                print!(".");
                if client
                    .submit_normal(
                        &sc.name,
                        &client.get_file(&files[0]).unwrap(),
                        files[0].name.split(".").collect::<Vec<&str>>().last().unwrap(),
                    )
                    .is_ok()
                {
                    submitted = true;
                }
            }
            println!("");
        }
    }
}

尚未实现

依赖

~19MB
~432K SLoC