https://learn.microsoft.com/en-us/training/modules/rust-introduction/2-rust-overview
https://www.runoob.com/rust/rust-tutorial.html
Rust playground 直接上手开玩!
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021
两数之和:
使用cargo方便的创建rust项目:
cargo new a_plus_b
cd a_plus_b
use std::io;
fn main() {
// Read input
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
// Split the input into two numbers
let numbers: Vec<i32> = input
.split_whitespace()
.map(|s| s.parse().expect("Parse error"))
.collect();
// Extract a and b
let a = numbers[0];
let b = numbers[1];
// Calculate the sum
let sum = a + b;
// Print the result
println!("{}", sum);
}
https://play.rust-lang.org/
fn main() {
// Simulated input
let input = String::from("1 2"); //手造input输入
// Split the input into two numbers
let numbers: Vec<i32> = input
.split_whitespace()
.map(|s| s.parse().expect("Parse error"))
.collect();
// Extract a and b
let a = numbers[0];
let b = numbers[1];
// Calculate the sum
let sum = a + b;
// Print the result
println!("{}", sum);
}