阅读程序 · 答案 HELLO, MY NAME IS LOSTMONKEY. · 考点:输入输出、位运算、分支结构、循环结构、字符串(string)
← 整套速查表 NOIP 普及组初赛 全部真题阅读程序写结果:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string st;
int i, len;
getline( cin, st );
len = st.size();
for ( i = 0; i < len; i++ )
if ( st[i] >= 'a' && st[i] <= 'z' )
st[i] = st[i] - 'a' + 'A';
cout << st << endl;
return(0);
}
输入:Hello, my name is Lostmonkey. 输出:________________________________
看到循环里 st[i] = st[i] - 'a' + 'A' → 小写转大写
死磕'-'32 数值;判断条件写成'Z';漏掉标点空格
考点:字符运算|循环控制
读入一行字符串,遍历每个字符:若为小写字母则转换为大写,其余字符保持不变,最后输出。