题目描述
给定两个由大小写字母和空格组成的字符串s1和 s2,它们的长度都不超过 100 个字符。判断压缩掉空格、并忽略大小写后,这两个字符串在是否相等。
解答要求时间限制:1000ms, 内存限制:100MB输入
输入两个字符串(分两行输入),只包含字母和空格。输入有多组测试,且到文件末尾结束。
输出
如果两个字符串相等则输出"Yes",否则输出"No"。
样例
输入样例 1 复制
asdf
aSDf
asdf aaa
aSdf aaa
输出样例 1
Yes
Yes
提示样例 1思路:先对两个字符串进行去空格,转换为小写字符串,然后比较字符串是否相等。
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string NoSpace(string &Str)
{
string Tempstr;
for(int i =0;i<Str.size();i++)
{
if(Str[i]!=' ')
Tempstr += (char)tolower(Str[i]);
}
return Tempstr;
}
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
string str1;
string str2;
while(getline(cin,str1)&&getline(cin,str2))
{
if(NoSpace(str1)==NoSpace(str2))
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}
原文链接: https://www.cnblogs.com/gcter/p/15466957.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/214560
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!