From e69f760f60c62eec323e6ffdbe9128371d76f968 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 12 May 2025 17:33:34 +0900 Subject: [PATCH] complete 2399.rs and rename storage/zeta/rust to rs --- run.py | 4 +++- space/src-rs/build.rs | 10 ++++++++-- storage/zeta/{rust => rs}/1000.rs | 0 storage/zeta/rs/completed/2399.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) rename storage/zeta/{rust => rs}/1000.rs (100%) create mode 100644 storage/zeta/rs/completed/2399.rs diff --git a/run.py b/run.py index 0c5598e..82892ce 100755 --- a/run.py +++ b/run.py @@ -203,13 +203,15 @@ def run(from_: str, target: str, verbose: bool): # build try: - subprocess.run( + s = subprocess.run( from_language.build_command, check=True, capture_output=True, text=True, cwd=from_language.working_dir, ) + print(s.stderr) + except subprocess.CalledProcessError as e: click.echo(">>>>>> [Error while BUILD process] >>>>>>") raise click.ClickException(e.stderr) diff --git a/space/src-rs/build.rs b/space/src-rs/build.rs index d7d50ce..bca8c7d 100644 --- a/space/src-rs/build.rs +++ b/space/src-rs/build.rs @@ -3,6 +3,8 @@ use std::fs; use std::path::Path; fn main() { + println!("cargo::rerun-if-changed=src/main.rs"); + // TODO: change to always execute build.rs let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".to_string()); let profile = env::var("PROFILE").unwrap(); let exe_name = env::var("CARGO_PKG_NAME").unwrap(); @@ -11,8 +13,12 @@ fn main() { let target_path = Path::new(&target_dir).join(&profile).join(&exe_name); let dest_path = Path::new("../../build").join("rs.out"); - + println!("cargo::warning={}", exe_name); if target_path.exists() { - fs::copy(&target_path, &dest_path).expect("Failed to copy executable"); + println!("cargo::warning=copy to {:#?}", dest_path); + match fs::copy(&target_path, &dest_path) { + Ok(_) => println!("cargo::warning=copy success"), + Err(_) => println!("cargo::warning=copy failed"), + } } } diff --git a/storage/zeta/rust/1000.rs b/storage/zeta/rs/1000.rs similarity index 100% rename from storage/zeta/rust/1000.rs rename to storage/zeta/rs/1000.rs diff --git a/storage/zeta/rs/completed/2399.rs b/storage/zeta/rs/completed/2399.rs new file mode 100644 index 0000000..8c8ed81 --- /dev/null +++ b/storage/zeta/rs/completed/2399.rs @@ -0,0 +1,29 @@ +use std::io; +use std::io::Write; + +fn mutual_difference(v: &Vec) -> i64 { + let mut s: i64 = 0; + for a in v { + for b in v { + s += (a - b).abs(); + } + } + return s; +} + +fn main() { + let stdout = io::stdout(); + let mut out = io::BufWriter::new(stdout.lock()); + + let mut line = String::new(); + let mut _trash = String::new(); + io::stdin().read_line(&mut _trash).expect("err"); + io::stdin().read_line(&mut line).expect("err"); + + let v = line + .trim() + .split(' ') + .map(|it| it.parse::().unwrap()) + .collect::>(); + writeln!(out, "{}", mutual_difference(&v)).expect("err"); +}