반응형
문제
https://www.acmicpc.net/problem/11654
11654번: 아스키 코드
알파벳 소문자, 대문자, 숫자 0-9중 하나가 주어졌을 때, 주어진 글자의 아스키 코드값을 출력하는 프로그램을 작성하시오.
www.acmicpc.net
풀이
- Character 자료형의 UnicodeScalar프로퍼티를 사용해서 쉽게 구할 수 있음
소스코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let word = Character(readLine()!) | |
print(word.asciiValue!) |
후기
- asciiValue 프로퍼티에 대해 알고 있다면 쉽게 풀 수 있는 문제
- 반대로는 어떻게 할까?
- UnicodeScalar(asciiValue)로 아스키 코드 값으로 글자를 구할 수 있음
반응형
'PS > 백준' 카테고리의 다른 글
[BOJ] 백준 10809 알파벳 찾기 (Swift) (1) | 2022.12.30 |
---|---|
[BOJ] 백준 11720 숫자의 합 (Swift) (0) | 2022.12.30 |
[BOJ] 백준 1065 한수 (Swift) (0) | 2022.12.30 |
[BOJ] 백준 4673 셀프 넘버 (Swift) (0) | 2022.12.30 |
[BOJ] 백준 4344 평균은 넘겠지 (Swift) (0) | 2022.12.28 |