컴퓨터 과학/자료구조, 알고리즘
[Rust로 백준 하루 하나] 5-1. 문자와 문자열
sans2
2024. 8. 21. 10:47
문제 (27866번)
단어 S와 정수 i가 주어졌을 때, S의 i번째 글자를 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 영어 소문자와 대문자로만 이루어진 단어 S가 주어진다. 단어의 길이는 최대 1000이다.
둘째 줄에 정수 i$i$가 주어진다. (1≤i≤|S|)
출력
S의 i번째 글자를 출력한다.
풀이
코드
use std::io;
fn main() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut index = String::new();
io::stdin().read_line(&mut index).unwrap();
let index: usize = index.trim().parse().unwrap();
let chars: Vec<char> = input.trim().chars().collect();
println!("{}", chars[index-1]);
}
해설
특이사항 없음
추가 학습
- 특이사항 없음