[Rust로 백준 하루 하나] 5-1. 문자와 문자열

김진산·2024년 8월 21일

Rust로 백준 하루 하나

목록 보기
43/138
post-thumbnail

문제 (27866번)

단어 S와 정수 i가 주어졌을 때, S의 i번째 글자를 출력하는 프로그램을 작성하시오.

입력

첫째 줄에 영어 소문자와 대문자로만 이루어진 단어 S가 주어진다. 단어의 길이는 최대 1000이다.

둘째 줄에 정수 iii가 주어진다. (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]);
}

해설

특이사항 없음


추가 학습

  • 특이사항 없음
profile
블록체인 개발자

0개의 댓글