*****又错一道,不知道为啥。。。 ybt【例5.19】字符串判等

【题目描述】

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

【输入】

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

【输出】

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

代码我觉得没啥问题,,,,会问老师的

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int n=256,m=256;
char a1[n],a2[n],b1[n],b2[n],top1,top2;
int main()
{
    cin.getline(a1,n);
    cin.getline(a2,n);
    int x=strlen(a1);
    int y=strlen(a2);
    for(int i=0;i<x;i++)
    {
        if(a1[i]<=90&&a1[i]>=65) a1[i]=a1[i]+32;
        if(a1[i]!=' ') 
        {
            b1[top1++]=a1[i];
        }
        
    }
    for(int j=0;j<y;j++)
    {
        if(a2[j]<=90&&a2[j]>=65) a2[j]=a2[j]+32;
        if(a2[j]!=' ') 
        {
            b2[top2++]=a2[j];
        }
    }
    if(top1==top2)
    {
        cout<<(strcmp(b1,b2)==0 ? "YES":"NO");
    }
    return 0;
    
}

 

posted @ 2022-02-19 11:23  你的小垃圾  阅读(139)  评论(0编辑  收藏  举报