励志用尽量少的代码做高效的表达
储备知识:
1、转化字母大小写→cctype头文件函数详解
注意点:
1、本题按要求4个if语句层层嵌套,一定要做到清晰、易懂,才能快速解题。
3、判断第三点时,用#include<cctyp>
中的toupper()
函数将两个字符串中所有字符全部转化为大写,再判断两个字符串是否相等,就可以很方便的解决这个问题。这种方法叫做“标准化”。
代码:
#include<bits/stdc++.h> //万能头文件
using namespace std;
int main() {
string s1, s2; cin >> s1 >> s2;
if(s1.length() != s2.length()) cout << 1;
else {
if(s1 == s2) cout << 2;
else {
for(int i = 0; i < s1.length(); i++) {
s1[i] = toupper(s1[i]); s2[i] = toupper(s2[i]); }
if(s1 == s2) cout << 3;
else cout << 4;
}
}
return 0;
}