字符串判等

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_15046309/article/details/82527877

描述

判断两个由大小写字母和空格组成的字符串在忽略大小写,且忽略空格后是否相等。

输入

两行,每行包含一个字符串。

输出

若两个字符串相等,输出YES,否则输出NO。

样例输入

a A bb BB ccc CCC
Aa BBbb CCCccc

样例输出

YES

字符的限制是单引号,不要写成双引号

统一变为大写字母在进行判断,C/C++有一个很好的工具

头文件#include<cctype>

toupper(字符);

#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main() {
	string a, c;
	string b, d;
	getline(cin, a);
	getline(cin, b);
	for (int i = 0; i < a.length(); i++)
	{
		//a[i] = toupper(a[i]);
		if (a[i]!=' ')
		{
			c += toupper(a[i]);
		}
	}
	for (int i = 0; i < b.length(); i++)
	{
	
		if (b[i] != ' ')
		{
			d += toupper(b[i]);
		}
	}
	if (c==d)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	system("pause");
}

猜你喜欢

转载自blog.csdn.net/qq_15046309/article/details/82527877
今日推荐