天天看點

字元串判等

描述

判斷兩個由大小寫字母和空格組成的字元串在忽略大小寫,且忽略空格後是否相等。

輸入

兩行,每行包含一個字元串。

輸出

若兩個字元串相等,輸出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");
}