├── .gitignore ├── LICENSE ├── question1 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question10 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question11 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question12 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question13 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question14 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question15 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question16 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question17 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question18 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question19 ├── Cargo.lock ├── Cargo.toml └── src │ ├── hoge.rs │ ├── lib.rs │ └── main.rs ├── question2 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question20 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question21 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question3 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question4 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question5 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question6 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question7 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── question8 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs └── question9 ├── Cargo.lock ├── Cargo.toml └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | */target 2 | */.vscode/ 3 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Akira Nishikawa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /question1/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question1" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question1/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question1" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question1/src/main.rs: -------------------------------------------------------------------------------- 1 | // println!でstr1が表示できるように4行目を修正してください 2 | fn main() { 3 | let str1 = String::from("hoge"); 4 | let str2 = str1; 5 | 6 | println!("Hello, world! {}", str1); 7 | } 8 | -------------------------------------------------------------------------------- /question10/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question10" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question10" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question10/src/main.rs: -------------------------------------------------------------------------------- 1 | // コンパイルが通るように修正してください 2 | fn main() { 3 | let values = [1, 2, 5, 10, 15]; 4 | let value = get(&values, 4); 5 | println!("{:?}", value); 6 | } 7 | 8 | fn get(&ary: &[i32], index: i64) -> Option { 9 | if ary.len() == 0 { 10 | None 11 | } else { 12 | ary.get(index) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /question11/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question11" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question11" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question11/src/main.rs: -------------------------------------------------------------------------------- 1 | // 43行目のコンパイルエラーを修正してください 2 | struct Latlng { 3 | lat: T, 4 | lng: T, 5 | } 6 | struct Hoge { 7 | a: i32, 8 | } 9 | 10 | trait Printable { 11 | fn print(&self); 12 | } 13 | impl Printable for Latlng 14 | where 15 | T: std::fmt::Display, 16 | { 17 | fn print(self: &Latlng) { 18 | println!("lat:{} lng:{}", self.lat, self.lng); 19 | } 20 | } 21 | 22 | fn main() { 23 | let hoge = Hoge { a: 100 }; 24 | let ll1: Latlng = Latlng { 25 | lat: 35.6804, 26 | lng: 139.7690, 27 | }; 28 | let ll2: Latlng = Latlng { 29 | lat: 12187059, 30 | lng: 47071786, 31 | }; 32 | let ll3: Latlng<&str> = Latlng { 33 | lat: "35.6804", 34 | lng: "47071786", 35 | }; 36 | let ll4: Latlng = Latlng { 37 | lat: hoge, 38 | lng: hoge, 39 | }; 40 | ll1.print(); 41 | ll2.print(); 42 | ll3.print(); 43 | ll4.print(); 44 | } 45 | -------------------------------------------------------------------------------- /question12/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question12" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question12" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question12/src/main.rs: -------------------------------------------------------------------------------- 1 | // コンパイルエラーを修正してください 2 | fn main() { 3 | let mut a = vec![3, 2, 1, 4, 5, 2]; 4 | a.push(3); 5 | let mut b = &a; 6 | println!("{:?}", b.pop()); 7 | } 8 | -------------------------------------------------------------------------------- /question13/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question13" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question13" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question13/src/main.rs: -------------------------------------------------------------------------------- 1 | // personが出力できるように構造体だけ修正してください 2 | #[derive(Debug)] 3 | struct Person { 4 | name: &str, 5 | } 6 | 7 | fn main() { 8 | let person = Person { name: "zakku" }; 9 | println!("{:?}", person); 10 | } 11 | -------------------------------------------------------------------------------- /question14/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question14" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question14" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question14/src/main.rs: -------------------------------------------------------------------------------- 1 | // question13の続きです。構造体とimplを修正してperson.name()が表示できるように修正してください 2 | #[derive(Debug)] 3 | struct Person { 4 | name: &str, 5 | } 6 | impl Person { 7 | fn name(&self) -> &str { 8 | self.name 9 | } 10 | } 11 | 12 | fn main() { 13 | let person = Person { name: "zakku" }; 14 | println!("{:?}", person.name()); 15 | } 16 | -------------------------------------------------------------------------------- /question15/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question15" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question15" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question15/src/main.rs: -------------------------------------------------------------------------------- 1 | // hello worldが出力されるように修正してください 2 | fn helloworld() -> &str { 3 | "hello world" 4 | } 5 | 6 | fn main() { 7 | println!("{}", helloworld()); 8 | } 9 | -------------------------------------------------------------------------------- /question16/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question16" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question16" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question16/src/main.rs: -------------------------------------------------------------------------------- 1 | // sayが実行できるように56行目を修正してください 2 | struct Nishikawa<'a> { 3 | name: &'a str, 4 | } 5 | 6 | struct Zakku<'a> { 7 | name: &'a str, 8 | } 9 | trait Owner { 10 | fn name(&self) -> &str; 11 | } 12 | impl<'a> Owner for Nishikawa<'a> { 13 | fn name(&self) -> &str { 14 | self.name 15 | } 16 | } 17 | 18 | impl<'a> Owner for Zakku<'a> { 19 | fn name(&self) -> &str { 20 | self.name 21 | } 22 | } 23 | 24 | struct Standard { 25 | speed: i32, 26 | } 27 | struct Van { 28 | speed: i32, 29 | } 30 | 31 | trait Car { 32 | fn speed(&self) -> i32; 33 | } 34 | 35 | impl Car for Standard { 36 | fn speed(&self) -> i32 { 37 | self.speed 38 | } 39 | } 40 | 41 | impl Car for Van { 42 | fn speed(&self) -> i32 { 43 | self.speed 44 | } 45 | } 46 | 47 | struct CarOwner { 48 | car: T, 49 | owner: O, 50 | } 51 | 52 | trait CarOwnerSay { 53 | fn say(&self); 54 | } 55 | 56 | impl CarOwnerSay for CarOwner { 57 | fn say(&self) { 58 | println!("{}, {}", self.car.speed(), self.owner.name()); 59 | } 60 | } 61 | 62 | fn main() { 63 | let owner = Nishikawa { name: "nishikawa" }; 64 | let car = Van { speed: 100 }; 65 | let car_owner = CarOwner { 66 | car: car, 67 | owner: owner, 68 | }; 69 | car_owner.say(); 70 | } 71 | -------------------------------------------------------------------------------- /question17/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question17" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question17/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question17" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question17/src/main.rs: -------------------------------------------------------------------------------- 1 | // mainのコードが実行できるように構造体を修正してください 2 | struct Hoge { 3 | a: T, 4 | b: T, 5 | } 6 | fn main() { 7 | let x = Hoge { a: 1, b: "aiueo" }; 8 | 9 | println!("{}, {}", x.a, x.b); 10 | } 11 | -------------------------------------------------------------------------------- /question18/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question18" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question18/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question18" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question18/src/main.rs: -------------------------------------------------------------------------------- 1 | // コンパイルが通るように修正してください。 2 | struct Standard { 3 | speed: i32, 4 | } 5 | 6 | struct SportsCar { 7 | speed: i32, 8 | turbo: i32, 9 | } 10 | 11 | trait Car { 12 | fn speed(&self) -> i32; 13 | } 14 | 15 | impl Car for Standard { 16 | fn speed(&self) -> i32 { 17 | self.speed 18 | } 19 | } 20 | 21 | impl Car for SportsCar { 22 | fn speed(&self) -> i32 { 23 | self.speed 24 | } 25 | } 26 | 27 | fn hoge(c: T) -> i32 { 28 | c.speed() 29 | } 30 | 31 | fn main() { 32 | println!("{}", hoge(Standard { speed: 30 })); 33 | println!("{}", hoge(SportsCar { speed: 30, turbo: 40 })); 34 | } 35 | -------------------------------------------------------------------------------- /question19/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question19" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question19/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question19" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question19/src/hoge.rs: -------------------------------------------------------------------------------- 1 | fn hoge() { 2 | println!("hogehoge"); 3 | } 4 | -------------------------------------------------------------------------------- /question19/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod hoge; 2 | -------------------------------------------------------------------------------- /question19/src/main.rs: -------------------------------------------------------------------------------- 1 | // コンパイルが通るように修正してください 2 | use question19::hoge::hoge; 3 | 4 | fn main() { 5 | hoge(); 6 | } 7 | -------------------------------------------------------------------------------- /question2/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question2" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question2" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question2/src/main.rs: -------------------------------------------------------------------------------- 1 | // matchを使用したままコンパイルが通るように修正してください。 2 | fn main() { 3 | println!("8 * 8 = {}", square(Some(8)).unwrap_or(0)); 4 | } 5 | 6 | fn square(x: Option) -> Option { 7 | match x { 8 | Ok(i) => Ok(i * i), 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /question20/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question20" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question20" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question20/src/main.rs: -------------------------------------------------------------------------------- 1 | // SwordとHeroのメンバ変数nameをstr型のまま、lifetime識別子を使用してコンパイルが通るように修正してください 2 | struct Sword { 3 | name: str, 4 | damage: i32, 5 | } 6 | 7 | struct Hero { 8 | name: str, 9 | hp: i32, 10 | sword: Option, 11 | } 12 | 13 | impl Hero { 14 | pub fn attack(&self) { 15 | println!("{}は攻撃した", self.name); 16 | if let Some(s) = &self.sword { 17 | println!("敵に{}ダメージ与えた", s.damage); 18 | } else { 19 | println!("敵にダメージを与えられない"); 20 | } 21 | } 22 | } 23 | 24 | fn main() { 25 | let s: Sword = Sword { 26 | name: "漆黒の剣", 27 | damage: 10, 28 | }; 29 | let h: Hero = Hero { 30 | name: "ひろあき", 31 | hp: 100, 32 | sword: Some(s), 33 | }; 34 | 35 | h.attack(); 36 | } 37 | -------------------------------------------------------------------------------- /question21/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question21" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question21" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question21/src/main.rs: -------------------------------------------------------------------------------- 1 | // コンパイルエラーを修正し、hashの中身が表示されるようにしてください 2 | use std::collections::HashMap; 3 | fn hoge(a: &HashMap) { 4 | a.insert(String::from("Hoge"), String::from("Huga")); 5 | } 6 | 7 | fn main() { 8 | let hash: HashMap = HashMap::new(); 9 | hoge(&hash); 10 | println!("{:?}", hash); 11 | } 12 | -------------------------------------------------------------------------------- /question3/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question3" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question3" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question3/src/main.rs: -------------------------------------------------------------------------------- 1 | // countの値が出力されるように1箇所修正してください 2 | fn main() { 3 | let count = 0u32; 4 | while count < 10 { 5 | count += 1; 6 | println!("count={}", count); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /question4/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question4" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question4/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question4" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question4/src/main.rs: -------------------------------------------------------------------------------- 1 | // 7行目のscoresが表示されるように修正してください 2 | fn main() { 3 | let scores = vec![100, 92, 84, 75, 98, 81]; 4 | for score in scores.into_iter() { 5 | println!("{}", score); 6 | } 7 | println!("{:?}", scores); 8 | } 9 | -------------------------------------------------------------------------------- /question5/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question5" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question5/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question5" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question5/src/main.rs: -------------------------------------------------------------------------------- 1 | // scoreに値を加算できるようにしてください。 2 | fn main() { 3 | let mut scores = vec![100, 92, 84, 75, 98, 81]; 4 | for score in scores.iter_mut() { 5 | score += 10; 6 | } 7 | println!("{:?}", scores); 8 | } 9 | -------------------------------------------------------------------------------- /question6/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question6" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question6/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question6" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question6/src/main.rs: -------------------------------------------------------------------------------- 1 | // 干支が表示できるように修正してください。 2 | const ETO: [&str; 12] = [ 3 | "さる", 4 | "とり", 5 | "いぬ", 6 | "い", 7 | "ネズミ", 8 | "うし", 9 | "とら", 10 | "う", 11 | "たつ", 12 | "み", 13 | "うま", 14 | "未", 15 | ]; 16 | fn eto(year: u32) { 17 | let org = 0; 18 | let diff = ((year - org) % 12); 19 | println!("{}", ETO[diff]); 20 | } 21 | fn main() { 22 | // 干支表示 23 | eto(2031); 24 | } 25 | -------------------------------------------------------------------------------- /question7/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question7" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question7/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question7" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question7/src/main.rs: -------------------------------------------------------------------------------- 1 | // コンパイルが通るように修正してください 2 | struct Point { 3 | x: i32, 4 | y: i32, 5 | } 6 | 7 | fn addpoint(p1: Point, p2: Point) -> Point { 8 | p1.x += p2.x; 9 | p1.y += p2.y; 10 | 11 | p1 12 | } 13 | 14 | fn main() { 15 | let p1: Point = Point { x: 1, y: 3 }; 16 | let p2: Point = Point { x: 2, y: 4 }; 17 | 18 | let p3 = addpoint(p1, p2); 19 | println!("{} {}", p3.x, p3.y); 20 | } 21 | -------------------------------------------------------------------------------- /question8/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question8" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question8/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question8" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question8/src/main.rs: -------------------------------------------------------------------------------- 1 | // 4行目を修正してhogeを出力してください。 2 | fn main() { 3 | let a = Some(String::from("hoge")); 4 | println!("{}", a); 5 | } 6 | -------------------------------------------------------------------------------- /question9/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "question9" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /question9/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "question9" 3 | version = "0.1.0" 4 | authors = ["akiranishikawa "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /question9/src/main.rs: -------------------------------------------------------------------------------- 1 | // 7行目を直してコンパイルエラーを解消してください。 2 | #[derive(Debug)] 3 | struct Person { 4 | name: String, 5 | } 6 | 7 | fn name_longer(a: &Person, b: &Person) -> &Person { 8 | if a.name.len() > b.name.len() { 9 | a 10 | } else { 11 | b 12 | } 13 | } 14 | 15 | fn main() { 16 | let a = Person { 17 | name: String::from("zakku"), 18 | }; 19 | let b = Person { 20 | name: String::from("nishikawa"), 21 | }; 22 | 23 | println!("{:?}", name_longer(&a, &b)); 24 | } 25 | --------------------------------------------------------------------------------