-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew
executable file
·66 lines (48 loc) · 1.6 KB
/
new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# bin/new-problem, My solutions to various Leetcode puzzles.
# Copyright (C) 2024, Savio Sena <[email protected]>
#
# Create the necessary files to work on a new problem.
target_dir=src/bin
if [ ! -d "./$target_dir" ]; then
printf "error: you must run this script from the root of the repository.\n" >&2
exit 2
fi
if [ $# -ne 2 ]; then
printf "Usage: %s <problem-name> <problem-id>\n" "$(basename $0)" >&2
exit 1
fi
problem_name="$1"
problem_id="$2"
problem_title=$(echo "$problem_name" | sed 's/-/ /g' |
awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1')
problem_function=$(echo "$problem_name" | sed 's/-/_/g')
problem_file="$target_dir/$problem_name.rs"
if [ -f "$problem_file" ]; then
printf "error: file already exists: %s\n" "$problem_file" >&2
exit 3
fi
cat <<EOF >>$problem_file && echo "created: ${problem_file}"
// ${problem_name}.rs, My solutions to various Leetcode puzzles.
// Copyright (C) 2024, Savio Sena <[email protected]>
//! # ${problem_id}. ${problem_title}
//!
//! - https://leetcode.com/problems/${problem_name}
use leetcode::*;
use std::error::Error;
struct Solution;
impl Solution {
pub fn ${problem_function}(nums: Vec<i32>) -> i32 {
0
}
}
fn main() -> Result<(), Box<dyn Error>> {
let mut input = std::io::stdin().lock();
let Vector(nums) = input.read_as::<Vector<i32>>()?;
let answer = Solution::${problem_function}(nums);
println!("{}", answer);
Ok(())
}
EOF
mkdir -p "input/$problem_name" && echo "created: input/${problem_name}"
mkdir -p "output/$problem_name" && echo "created: output/${problem_name}"