1 条题解
-
0
【深基2.例6】字母转换
解题思路
小写字母与对应大写字母在字母表中的相对位置相同,输出 c-a+A。
正确性说明
字符 c 与 a 的编码差给出零起始位置,加上 A 得到对应大写字母。
易错点
输出 char,避免直接输出整数编码。
复杂度
时间 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 << char(c - 'a' + 'A') << "\n"; return 0; }
- 1