2743:字符串判等

2743:字符串判等


总时间限制: 
1000ms 
内存限制: 
65536kB
描述 字符串的相关比较 strcmp strlen 最后为了容易比较 在字符串后加上 '\0' 代表字符串的结束

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

输入
两行,每行包含一个字符串。
输出
若两个字符串相等,输出YES,否则输出NO。
样例输入
a A bb BB ccc CCC
Aa BBbb CCCccc
样例输出
YES
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt","w",stdout);
    char c1[200], c2[200], c3[200], c4[200];
    gets(c1);
    //getchar();
    gets(c2);
    int len1 = strlen(c1);
    int len2 = strlen(c2);
    int index = 0;
    for(int i = 0; i < len1; i++){
        if(c1[i] != ' '){
            if(c1[i] >= 'A' && c1[i] <= 'Z'){
                c3[index++] = c1[i] - 'A' + 'a';
            }else {
                c3[index++] = c1[i];
            }
        }
    }
    c3[index] = '\0';
    index = 0;
    for(int i = 0; i < len2; i++){
        if(c2[i] != ' '){
            if(c2[i] >= 'A' && c2[i] <= 'Z'){
                c4[index++] = c2[i] - 'A' + 'a';
            }else {
                c4[index++] = c2[i];
            }
        }
    }
    c4[index] = '\0';
    //cout<<"s3:"<<c3<<",s4:"<<c4<<endl;

    /**
    * 设这两个字符串为str1,str2,
    * 若str1==str2,则返回零;
    * 若str1<str2,则返回负数;
    * 若str1>str2,则返回正数。
    **/
    if(strcmp(c3, c4) == 0){
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值