string中没有大小写转化的函数
所以要运用到transform的用法
用法如下,很简单,记住就好~
- 注意要加上头文件
#include<algorithm>
transform(s1.begin(),s1.end(),s1.begin(),::toupper);//变为大写
transform(s1.begin(),s1.end(),s1.begin(),::tolower);//变为小写
sdnu 1441字符串对比
题目很简单
if 判断即可,就是运用到了string的某些用法。
代码如下
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int main() {
string s1,s2;
cin>>s1>>s2;
if(s1.length()!= s2.length()) {
cout<<"1"<<'\n';
} else if(s1 == s2) {
cout<<"2"<<'\n';
} else {
transform(s1.begin(),s1.end(),s1.begin(),::toupper);
transform(s2.begin(),s2.end(),s2.begin(),::toupper);
if(s1 == s2)
cout<<"3"<<'\n';
else cout<<"4"<<'\n';
}
return 0;
}