Comprehensive Rust(繁体中文) 202406Lint)。 請注意,您可以使用 cargo fix 或編輯器,修正含有 help: ... 的錯誤或警告。 27.4 盧恩演算法 盧恩演算法 盧恩演算法可用於驗證信用卡號碼。這個演算法會將字串做為輸入內容,並執行下列操作來驗證信用卡號 碼: • Ignore all spaces. Reject number with fewer than two digits. • 從右到左,將偶數位的數字乘二。以數字 將數字乘二後,如果結果大於 9,請將每位數字相加。所以,7 乘二等於 14,那麼也就是 1 + 4 = 5。 • 將所有數字 (無論是否已乘二) 相加。 • 如果加總所得數字的末位是 0,代表信用卡卡號有效。 這裡提供的程式碼是盧恩演算法的錯誤實作示例,另外還有兩個基本單元測試,用於確認大部分演算法已 正確實作。 Copy the code below to https://play.rust-lang common crate that both the client and server can depend on. 34.1.7 改寫 API 讓我們為這個 API 擴充更多功能:我們想要讓用戶能在生日卡上指定幾行字: package com.example.birthdayservice; 193 /** Birthday service interface. */ interface IBirthdayService0 码力 | 356 页 | 1.41 MB | 1 年前3
共 1 条
- 1













