mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 23:09:18 +00:00
翻譯
This commit is contained in:
parent
ade5ab5600
commit
0e6eaed721
@ -1,24 +1,23 @@
|
||||
// quiz1.rs
|
||||
//
|
||||
// This is a quiz for the following sections:
|
||||
// - Variables
|
||||
// - Functions
|
||||
// 本測驗涵蓋以下章節:
|
||||
// - 變數
|
||||
// - 函數
|
||||
// - If
|
||||
//
|
||||
// Mary is buying apples. The price of an apple is calculated as follows:
|
||||
// - An apple costs 2 rustbucks.
|
||||
// - If Mary buys more than 40 apples, each apple only costs 1 rustbuck!
|
||||
// Write a function that calculates the price of an order of apples given the
|
||||
// quantity bought.
|
||||
// Mary 在買蘋果。蘋果的價格計算如下:
|
||||
// - 一個蘋果的價格是 2 rustbucks。
|
||||
// - 如果 Mary 買超過 40 個蘋果,每個蘋果的價格只需 1 rustbuck!
|
||||
// 寫一個函數來計算購買蘋果的總價格,給定購買的數量。
|
||||
//
|
||||
// No hints this time ;)
|
||||
// 這次沒有提示 ;)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Put your function here!
|
||||
// 把你的函數寫在這裡!
|
||||
// fn calculate_price_of_apples {
|
||||
|
||||
// Don't modify this function!
|
||||
// 不要修改這個函數!
|
||||
#[test]
|
||||
fn verify_test() {
|
||||
let price1 = calculate_price_of_apples(35);
|
||||
|
||||
@ -1,24 +1,23 @@
|
||||
// quiz2.rs
|
||||
//
|
||||
// This is a quiz for the following sections:
|
||||
// - Strings
|
||||
// - Vecs
|
||||
// - Move semantics
|
||||
// - Modules
|
||||
// - Enums
|
||||
// 本測驗涵蓋以下章節:
|
||||
// - 字串
|
||||
// - 向量 (Vec)
|
||||
// - 移動語義 (Move semantics)
|
||||
// - 模組 (Modules)
|
||||
// - 枚舉 (Enums)
|
||||
//
|
||||
// Let's build a little machine in the form of a function. As input, we're going
|
||||
// to give a list of strings and commands. These commands determine what action
|
||||
// is going to be applied to the string. It can either be:
|
||||
// - Uppercase the string
|
||||
// - Trim the string
|
||||
// - Append "bar" to the string a specified amount of times
|
||||
// The exact form of this will be:
|
||||
// - The input is going to be a Vector of a 2-length tuple,
|
||||
// the first element is the string, the second one is the command.
|
||||
// - The output element is going to be a Vector of strings.
|
||||
// 讓我們建立一個函數形式的小機器。作為輸入,我們將提供一個字串和命令的列表。
|
||||
// 這些命令決定了要對字串執行的操作。它可以是:
|
||||
// - 將字串轉為大寫
|
||||
// - 修剪字串
|
||||
// - 將 "bar" 附加到字串指定的次數
|
||||
// 具體形式如下:
|
||||
// - 輸入是一個長度為2的元組向量,
|
||||
// 第一個元素是字串,第二個是命令。
|
||||
// - 輸出是一個字串向量。
|
||||
//
|
||||
// No hints this time!
|
||||
// 這次沒有提示!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@ -31,12 +30,12 @@ pub enum Command {
|
||||
mod my_module {
|
||||
use super::Command;
|
||||
|
||||
// TODO: Complete the function signature!
|
||||
// TODO: 完成函數簽名!
|
||||
pub fn transformer(input: ???) -> ??? {
|
||||
// TODO: Complete the output declaration!
|
||||
// TODO: 完成輸出聲明!
|
||||
let mut output: ??? = vec![];
|
||||
for (string, command) in input.iter() {
|
||||
// TODO: Complete the function body. You can do it!
|
||||
// TODO: 完成函數體。你能做到的!
|
||||
}
|
||||
output
|
||||
}
|
||||
@ -44,7 +43,7 @@ mod my_module {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// TODO: What do we need to import to have `transformer` in scope?
|
||||
// TODO: 我們需要導入什麼來讓 `transformer` 在作用域內?
|
||||
use ???;
|
||||
use super::Command;
|
||||
|
||||
|
||||
@ -1,20 +1,16 @@
|
||||
// quiz3.rs
|
||||
//
|
||||
// This quiz tests:
|
||||
// - Generics
|
||||
// - Traits
|
||||
// 本測驗涵蓋:
|
||||
// - 泛型 (Generics)
|
||||
// - 特徵 (Traits)
|
||||
//
|
||||
// An imaginary magical school has a new report card generation system written
|
||||
// in Rust! Currently the system only supports creating report cards where the
|
||||
// student's grade is represented numerically (e.g. 1.0 -> 5.5). However, the
|
||||
// school also issues alphabetical grades (A+ -> F-) and needs to be able to
|
||||
// print both types of report card!
|
||||
// 一所虛構的魔法學校有一個用 Rust 編寫的新報告卡生成系統!目前該系統僅支持創建成績以數字表示的報告卡(例如 1.0 -> 5.5)。
|
||||
// 然而,學校也發佈了字母成績(A+ -> F-),需要能夠打印這兩種類型的報告卡!
|
||||
//
|
||||
// Make the necessary code changes in the struct ReportCard and the impl block
|
||||
// to support alphabetical report cards. Change the Grade in the second test to
|
||||
// "A+" to show that your changes allow alphabetical grades.
|
||||
// 在 ReportCard 結構和 impl 塊中做出必要的代碼更改,以支持字母報告卡。
|
||||
// 在第二個測試中將 Grade 更改為 "A+",以表明您的更改允許字母成績。
|
||||
//
|
||||
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.
|
||||
// 執行 `rustlings hint quiz3` 或使用 `hint` watch 子命令獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@ -50,7 +46,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn generate_alphabetic_report_card() {
|
||||
// TODO: Make sure to change the grade here after you finish the exercise.
|
||||
// TODO: 完成練習後,請確保在這裡更改成績。
|
||||
let report_card = ReportCard {
|
||||
grade: 2.1,
|
||||
student_name: "Gary Plotter".to_string(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user