天天看点

蓝桥杯练习BASIC-15 字符串对比题目大意完整代码

题目大意

蓝桥杯练习BASIC-15 字符串对比题目大意完整代码

标签:字符串,大小写

点击进入题目

完整代码

/*
strcmp(char* s1, char*s2)区分大小写比较函数
stricmp(char* s1, char*s2)不区分大小写比较函数
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	string str1, str2;
	cin >> str1 >> str2;
	if (str1.size() != str2.size()) {//判断长度是否相等,不等为第一种情况
		cout << "1" << endl;
	}
	else {
		if (strcmp(str1.c_str(),str2.c_str())==0){//若长度相等,判断是否是完全一样的字符串,完全一样为第二种情况
			cout << "2" << endl;
		}
		else {
			if (_stricmp(str1.c_str(), str2.c_str())==0) {//如果不完全一样,则不区分大小写看是否一样,不区分大小写一样为第三种情况
				cout << "3" << endl;
			}
			else {//都不是为第四种情况
				cout << "4" << endl;
			}
		}
	}
}
           

继续阅读