解题思路: 

利用STL的 transform()函数 可以把字符串全部转成大写或者小写,对第三的判断非常简单!!


注意事项:   transform()的参数介绍  (原字符串起始,原字符串结束,新字符串起始,大写或小写)

   注意最后一定要带上    ::toupper或者 ::tolower 因为他们是属于string类的toupper函数和tolower函数
参考代码:

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s1,s2;
    cin>>s1>>s2;

   if(s1.length()!=s2.length()){    //若长度不等,则为1
		  cout<<"1";
	}
	else {   //后面都是长度不等的情况
		if(s1==s2) cout<<"2";
	  else {
	  	transform(s1.begin(),s1.end(),s1.begin(),::toupper); //全部转成大写
	    transform(s2.begin(),s2.end(),s2.begin(),::toupper);
	    if(s1==s2) cout<<"3";   
	    else  cout<<"4";
	    
	  }
	}
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区