字符串对比之美

代码如下:

#include <vector>    
#include <iostream>    
#include<cmath>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int flag = 0;
	string a, b;
	cin >> a >> b;
	if (a.size() == b.size())//字符串大小相等
	{
		if (!a.compare(b))//字符串相等a==b
		{
			flag = 2;
		}
		else
		{
			transform(a.begin(), a.end(),a.begin(), toupper);
			transform(b.begin(), b.end(), b.begin(), toupper);
			if (a == b)//不区分大小写相等
			{
				flag = 3;
			}
			else
			{
				flag = 4;
			}
		}
	}
	else
	{
		flag = 1;
	}
	cout << flag << endl;
	system("pause");
	return 0;
}
发布了79 篇原创文章 · 获赞 151 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44350205/article/details/104247373