# Code Verification Steps
Before committing changes or submitting code, always run these commands in order:
1. `cargo fmt` - Format the code according to Rust style guidelines
2. `cargo clippy` - Check for common mistakes and verify code quality
3. `cargo test` - Run the test cases to verify functionality
This ensures that the code is:
- Properly formatted
- Free of common programming errors
- Functionally correct according to test cases
# Baekjoon Online Judge (BOJ) Rules
## File Structure
When adding a new BOJ problem solution:
1. Create a new file in the appropriate directory:
- File should be named `p{number}.rs`
- Place it in `src/boj/p{n}k/` where n is the first digits of the problem number
- Reference nearby files in the same directory for consistent formatting and structure
Example: For problem 1000, create `src/boj/p1k/p1000.rs` and check other files in `p1k/`
2. Register the module in the corresponding module file:
- Add `mod p{number};` to the appropriate `p{n}k.rs` file
- Check the existing module declarations for correct ordering
Example: Add `mod p1000;` to `src/boj/p1k.rs`
## Input Function Usage Guide
When reading input values:
1. For single value:
- Use `read_value(read_line(reader))` function
Example: `let n: usize = read_value(read_line(reader));`
2. For multiple values in one line:
- Use `read_values_as!` macro when reading multiple different types
Example: `let (n, m): (usize, i32) = read_values_as!(read_line(reader), usize, i32);`
3. For n values of the same type:
- Use `read_n_values(reader, n)` function
Example: `let arr: Vec<i32> = read_n_values(reader, n);`
4. For reading a matrix:
- Use `read_map(reader, rows, cols)` function
Example: `let matrix: Vec<Vec<i32>> = read_map(reader, n, m);`
## Test Code Structure Guide
When writing test functions:
1. Test case struct should be defined as:
```rust
struct TestCase {
s: String, // input string
want: String, // expected output string
}
```
2. Test cases iteration should follow:
```rust
for (i, data) in vec![
TestCase {
s: "input".to_string(),
want: "expected".to_string(),
},
].iter().enumerate()
```
3. Assertion format:
```rust
assert_eq!(
got.trim(),
data.want.trim(),
"failed at {} with {}",
i,
data.s
);
```
## Commit Message Format
When solving problems from Baekjoon Online Judge, use the following commit message format:
```
boj: solve {problem_number} {problem_title}
- https://www.acmicpc.net/problem/{problem_number}
```
Example:
```
boj: solve 1000 A+B
- https://www.acmicpc.net/problem/1000
```
To handle multi-line commit messages, use printf with git commit -F:
```
printf "boj: solve {problem_number} {problem_title}\n\n- https://www.acmicpc.net/problem/{problem_number}" | git commit -F -
```
Example:
```
printf "boj: solve 1000 A+B\n\n- https://www.acmicpc.net/problem/1000" | git commit -F -
```
## Code Submission Guide
When preparing code for submission:
1. Use @submit_template.rs as the base template
2. Make sure to name the solution function as solve#### where #### is the problem number
- Example: For problem 1000, use solve1000 instead of just solve
3. When the code is ready, paste the complete submission code in the chat
- This allows for a final review before actual submission
4. The submission code should be self-contained and include all necessary functions from the template
5. NEVER modify the template's boilerplate code:
- Do not modify the read_values_as! macro
- Do not modify the read_value and read_line functions
- Do not change the function order specified in the template
- Only implement the problem-specific logic in the solve#### function
## Code Style Guide
When writing solution code:
1. Solution function should:
- Be named solve#### where #### is the problem number
- NOT be public (no pub keyword)
- Have #[allow(dead_code)] attribute
Example:
```rust
#[allow(dead_code)]
fn solve1000(reader: &mut impl BufRead, writer: &mut impl Write)
```
2. Test function should:
- Include problem URL and title as comments above the #[test] attribute
Example:
```rust
// https://www.acmicpc.net/problem/1000
// A+B
#[test]
fn test_solve1000()
```
3. Import statements should:
- Import read_values_as! macro directly from crate root: `use crate::read_values_as;`
- Import other io utilities from utils::io: `use crate::utils::io::{read_line, read_n_values};`
Example:
```rust
use crate::read_values_as;
use crate::utils::io::{read_line, read_n_values};
use std::io::{BufRead, Write};
```
golang
rust
First Time Repository
1 day 1 coding with rust-lang
Rust
Languages:
Rust: 1193.0KB
Created: 12/8/2019
Updated: 1/21/2025
All Repositories (1)
1 day 1 coding with rust-lang