Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

아모에요

[BOJ/백준][Rust] 1000 A+B 본문

Study/PS

[BOJ/백준][Rust] 1000 A+B

dys4nt 2023. 6. 18. 14:27

ID dys4nt로 새로운 백준 PS 계정을 만들었다.

Rust 언어를 공부할 겸 Rust로 solved.ac CLASS들을 깨보겠다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::io;
 
fn main(){
    let mut s = String::new();
    io::stdin().read_line(&mut s);
    let li = s.split_whitespace();
    let mut x: i32 = 0;
 
    for num in li{
        x += num.parse::<i32>().unwrap();
    }
 
    println!("{}",x);
}
cs

 

use std::io를 이용해서 stdin, stdout를 사용한다.

 

mutable(가변) 변수 s를 String::new()로 설정한다.

io::stdin().read_line(&mut s)에서 s에 입력을 받는다.

li에 split한 s를 할당한다.

 

x이라는 i32형 변수를 할당한다.

 

li의 모든 값에 대해서 i32형태로 바꾸고 x에 더한다.

 

x를 출력한다.

'Study > PS' 카테고리의 다른 글

[BOJ/백준][Rust] 1008 A/B  (0) 2023.06.18
[BOJ/백준][Rust] 1001 A-B  (0) 2023.06.18
[BOJ/백준] 1956 - 운동  (0) 2023.06.11