Learning
This commit is contained in:
BIN
BasicSyntax/test1/src/apple.exe
Normal file
BIN
BasicSyntax/test1/src/apple.exe
Normal file
Binary file not shown.
BIN
BasicSyntax/test1/src/apple.pdb
Normal file
BIN
BasicSyntax/test1/src/apple.pdb
Normal file
Binary file not shown.
21
BasicSyntax/test1/src/apple.rs
Normal file
21
BasicSyntax/test1/src/apple.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::io;
|
||||
|
||||
fn pr(a:i64){
|
||||
if a > 1 {
|
||||
println!("Today, I ate {} apples.", a)
|
||||
}
|
||||
else if a == 1 || a == 0 {
|
||||
println!("Today, I ate {} apple.", a)
|
||||
}
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let mut input = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("");
|
||||
|
||||
let mut a = input.trim().parse::<i64>().expect("");
|
||||
pr(a)
|
||||
|
||||
}
|
||||
BIN
BasicSyntax/test1/src/main.exe
Normal file
BIN
BasicSyntax/test1/src/main.exe
Normal file
Binary file not shown.
BIN
BasicSyntax/test1/src/main.pdb
Normal file
BIN
BasicSyntax/test1/src/main.pdb
Normal file
Binary file not shown.
27
BasicSyntax/test1/src/main.rs
Normal file
27
BasicSyntax/test1/src/main.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::io;
|
||||
|
||||
fn add(a:i64, b:i64) -> i64 {
|
||||
return a + b ;
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let mut input = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("");
|
||||
|
||||
// 用空格拆分字符串
|
||||
let nums: Vec<i64> = input
|
||||
.trim() // 去掉换行符
|
||||
.split_whitespace() // 按空格拆分
|
||||
.map(|s| s.parse::<i64>().expect("请输入有效整数")) // 转换为整数
|
||||
.collect();
|
||||
|
||||
// 假设用户输入了两个整数
|
||||
let a = nums[0];
|
||||
let b = nums[1];
|
||||
|
||||
let c = add(a, b);
|
||||
println!("{}", c);
|
||||
}
|
||||
22
BasicSyntax/test1/src/two.rs
Normal file
22
BasicSyntax/test1/src/two.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use std::io;
|
||||
|
||||
fn add(a : i64, b : i64) -> i64 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let mut sa = String::new();
|
||||
let mut sb = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut sa)
|
||||
.expect("");
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut sb)
|
||||
.expect("");
|
||||
|
||||
let a: i64 = sa.trim().parse::<i64>().expect("");
|
||||
let b: i64 = sb.trim().parse::<i64>().expect("");
|
||||
let c = add(a, b);
|
||||
println!("{}", c);
|
||||
}
|
||||
Reference in New Issue
Block a user