![[백준 / BOJ] 11654번 아스키 코드 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FnCzgG%2FbtrJlUIFiTo%2FhKxVRHKcs7kj5hMUC4THOK%2Fimg.png)
[백준 / BOJ] 11654번 아스키 코드 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 1. 17. 07:24
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/11654
11654번: 아스키 코드
알파벳 소문자, 대문자, 숫자 0-9중 하나가 주어졌을 때, 주어진 글자의 아스키 코드값을 출력하는 프로그램을 작성하시오.
www.acmicpc.net
문제

문제 풀이
숫자를 이용해서 문자를 표현하도록 하려면 숫자를 문자에 매핑시켜야 한다. 이를 연결하는 방법 중 아스키 코드를 쓰는 방법이 있고, 아래의 표를 참고하면 프로그래밍 언어에서 변환하는 기준을 찾을 수 있다. C++에서는 int, char 변수에 (char), (int)를 붙이면 알아서 변환되고, python에서는 ord명령어를 사용하면 된다.

C++ 코드 전문
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
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
char c; | |
cin >> c; | |
cout << (int)c; | |
} |
Python 코드 전문
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
c = input() | |
print(ord(c)) |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10809번 알파벳 찾기 (C++, Python) (0) | 2022.01.17 |
---|---|
[백준 / BOJ] 11720번 숫자의 합 (C++, Python) (0) | 2022.01.17 |
[백준 / BOJ] 1065번 한수 (C++, Python) (0) | 2021.09.07 |
[백준 / BOJ] 4673번 셀프 넘버 (C++, Python) (0) | 2021.09.06 |
[백준 / BOJ] 15596번 정수 N개의 합 (C++, Python) (0) | 2021.09.05 |
@Reo :: 코드 아카이브
자기계발 블로그