分析:
可以用字符数组实现,也可以用string类实现
字符数组代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
char s[105];
cin >> s;
for(int i=0;i<strlen(s);i++){
if(s[i]>='a' and s[i]<='z') s[i] -= 32;
}
cout << s << endl;
return 0;
}
string类代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
for(int i=0; i<s.length();i++){
//if(s[i]>='a' and s[i]<='z') s[i] -= 32;
s[i] = toupper(s[i]); //toupper()函数,直接转成大写
}
cout << s << endl;
return 0;
}