1 条题解
-
0
练40.1 小写变大写
解题思路
小写字母在字母表中的偏移为c-a,同偏移加到A即得大写。
正确性说明
计算规则直接来自题目定义。按所述顺序处理时,已完成部分的结果被准确保存在累加量、计数或当前状态中;下一步只加入新增贡献。最终得到完整要求的结果。
易错点
输出字符而不是编码整数。
复杂度
时间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