1 条题解
-
0
练9.2 打印ASCII码
解题思路
读入字符,把它转换为整数后输出。
正确性说明
整数转换表示该字符存储的 ASCII 数值。
易错点
读取的是可见字符,不是数字编码文本。
复杂度
本题输入规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); char c; cin >> c; cout << int(static_cast<unsigned char>(c)) << "\n"; return 0; }
- 1