1138:将字符串中的小写字母转换成大写字母(C C++)

【题目描述】

给定一个字符串,将其中所有的小写字母转换成大写字母。

【输入】

输入一行,包含一个字符串(长度不超过100,可能包含空格)。

【输出】

输出转换后的字符串。

【输入样例】

helloworld123Ha

【输出样例】

HELLOWORLD123HA

【代码】

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    
    
	char a[101];
	gets(a);//gets 可以获取空格  cin不行 
	int len=strlen(a);//长度 
	for(int i=0;i<len;i++)
	{
    
    
		if( (a[i]>='a' && a[i]<='z') )  cout<< char(a[i]-32); //小写则-32变为大写 
		else cout<<a[i];		//否则正常输出 				
	} 
}

猜你喜欢

转载自blog.csdn.net/weixin_50901683/article/details/109097390
今日推荐