Skip to content
Snippets Groups Projects
Commit c43ab3d5 authored by Alfex4936's avatar Alfex4936
Browse files

Merge hi-rust

parent d75be358
Branches
No related tags found
No related merge requests found
Pipeline #6338 passed
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -71,7 +71,7 @@ $ Hello, world! (stdout) ...@@ -71,7 +71,7 @@ $ Hello, world! (stdout)
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -78,7 +78,7 @@ fn main() { ...@@ -78,7 +78,7 @@ fn main() {
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -102,7 +102,7 @@ let my_number_string = my_number.to_string(); // "42"라는 String 타입으로 ...@@ -102,7 +102,7 @@ let my_number_string = my_number.to_string(); // "42"라는 String 타입으로
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -80,7 +80,7 @@ if __name__ == "__main__": ...@@ -80,7 +80,7 @@ if __name__ == "__main__":
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -91,7 +91,7 @@ fn main() { ...@@ -91,7 +91,7 @@ fn main() {
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -168,7 +168,7 @@ fn main() { ...@@ -168,7 +168,7 @@ fn main() {
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -94,7 +94,7 @@ Rust에서는 결과를 나타내기 위해 Result 열거형을 사용합니다. ...@@ -94,7 +94,7 @@ Rust에서는 결과를 나타내기 위해 Result 열거형을 사용합니다.
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -45,6 +45,91 @@ ...@@ -45,6 +45,91 @@
<li><a href="https://doc.rust-lang.org/1.30.0/book/2018-edition/ch03-02-data-types.html" target="_blank" rel="noopener">Website: Rust Book 2018 - 기본 데이터 유형에 대한 자세한 설명</a></li> <li><a href="https://doc.rust-lang.org/1.30.0/book/2018-edition/ch03-02-data-types.html" target="_blank" rel="noopener">Website: Rust Book 2018 - 기본 데이터 유형에 대한 자세한 설명</a></li>
<li><a href="https://cheats.rs/#basic-types" target="_blank" rel="noopener">Website: Rust Cheat Sheet - Data Types</a></li> <li><a href="https://cheats.rs/#basic-types" target="_blank" rel="noopener">Website: Rust Cheat Sheet - Data Types</a></li>
</ul> </ul>
<div> <button type="button" class="collapsible">정답 보기</button> <div class="content"> <pre><code class="rust">enum Shape {
Circle(f64), // 반지름
Rectangle(f64, f64), // 가로, 세로
Triangle(f64, f64, f64), // 세 변의 길이
}
// 넓이를 계산하는 함수
fn area(shape: &Shape) -> f64 {
match shape {
Shape::Circle(r) => 3.14 * r * r,
Shape::Rectangle(w, h) => w * h,
Shape::Triangle(a, b, c) => {
// 삼각형의 넓이 공식
let s = (a + b + c) / 2.0;
let area = s * (s - a) * (s - b) * (s - c);
// 넓이가 음수면 에러 발생
if area < 0.0 {
panic!("Invalid triangle");
} else {
area.sqrt()
}
}
}
}
// 둘레를 계산하는 함수
fn perimeter(shape: &Shape) -> f64 {
match shape {
Shape::Circle(r) => 2.0 * 3.14 * r,
Shape::Rectangle(w, h) => 2.0 * (w + h),
Shape::Triangle(a, b, c) => {
// 삼각형의 둘레 공식
let p = a + b + c;
// 둘레가 음수면 에러 발생
if p < 0.0 {
panic!("Invalid triangle");
} else {
p
}
}
}
}
// 정사각형인지 판별하는 함수
fn is_square(shape: &Shape) -> bool {
match shape {
Shape::Circle(_) => false,
Shape::Rectangle(w, h) => w == h,
Shape::Triangle(_, _, _) => false,
}
}
// 결과
/*
원 넓이: 12.56
사각형 넓이: 12
삼각형 넓이: 6
원 둘레: 12.56
사각형 둘레: 14
삼각형 둘레: 12
원이 정사각형인가? false
사각형이 정사각형인가? false
삼각형이 정사각형인가? false
*/
fn main() {
// Shape 타입의 값들을 생성합니다.
let circle = Shape::Circle(2.0);
let rectangle = Shape::Rectangle(3.0, 4.0);
let triangle = Shape::Triangle(3.0, 4.0, 5.0);
// 각 도형의 넓이를 출력합니다.
println!("원 넓이: {}", area(&circle));
println!("사각형 넓이: {}", area(&rectangle));
println!("삼각형 넓이: {}", area(&triangle));
// 각 도형의 둘레를 출력합니다.
println!("원 둘레: {}", perimeter(&circle));
println!("사각형 둘레: {}", perimeter(&rectangle));
println!("삼각형 둘레: {}", perimeter(&triangle));
// 각 도형이 정사각형인지 출력합니다.
println!("원이 정사각형인가? {}", is_square(&circle));
println!("사각형이 정사각형인가? {}", is_square(&rectangle));
println!("삼각형이 정사각형인가? {}", is_square(&triangle));
}</code></pre> </div> </div>
<div class="bottomnav"> <div class="bottomnav">
<span class="back"><a href="20_ko.html" rel="prev">❮ 이전</a></span> <span class="back"><a href="20_ko.html" rel="prev">❮ 이전</a></span>
<span class="next"><a href="chapter_2_ko.html" rel="next">다음 ❯</a></span> <span class="next"><a href="chapter_2_ko.html" rel="next">다음 ❯</a></span>
...@@ -69,7 +154,7 @@ ...@@ -69,7 +154,7 @@
</script> </script>
<footer> <footer>
<p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p> <p><a target="_blank" rel="noopener" href="https://www.youtube.com/c/SoftwareToolTime">아주대학교 Software Tool Time</a> - Rust 튜토리얼 (Basic)</p>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment