17.字符串判等
描述
判断两个由大小写字母和空格组成的字符串在忽略大小写,且忽略空格后是否相等。
输入两行,每行包含一个字符串。输出若两个字符串相等,输出YES,否则输出NO。样例输入a A bb BB ccc CCC Aa BBbb CCCccc样例输出
YES
#include <stdio.h>
#include <string.h>
#define N 1005
char a[N], b[N], c[N];
int main()
{
int i, j, len, ok;
gets(a);
gets(b);
for (i = 0, j = 0; a[i]; i++)
{
if (a[i] == ' ') continue;
if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 32;
c[j++] = a[i];
}
len = j;
ok = 1;
for (i = 0, j = 0; b[i]; i++)
{
if (b[i] == ' ') continue;
if (b[i] >= 'A' && b[i] <= 'Z') b[i] += 32;
if (b[i] != c[j++])
{
ok = 0;
break;
}
}
if (ok && j == len) printf("YES\n");
else printf("NO\n");
return 0;
}