用C++编写一个大小写转换小程序

2025-02-27 21:10:40
推荐回答(2个)
回答1:

#include
#include
using namespace std;
int main()
{
string s;
char *p;int d=0,x=0; //存放大写与小写的变量
cin>>s;
for(p=s.begin();p!=s.end();p++)
{
if(*p>='A'&&*p<='Z')
{ *p=*p+32;x+=1 if(*p>='a'&&*p<='z') *p=*p-32;d+=1

}
cout<return 0;
}

回答2:

#include
#include

using namespace std;

int main()
{
string s;
string::iterator p;
int d=0,x=0; //存放大写与小写的变量
cin>>s;
for(p=s.begin();p!=s.end();*p++)
{
if(*p>='A'&&*p<='Z')
{ x+=1 ;}
if(*p>='a'&&*p<='z')
{d+=1;}
}
cout<cout<<"共"<return 0;
}