zoukankan      html  css  js  c++  java
  • 52. 字符串相等 A

    题目描述

    给定两个由大小写字母和空格组成的字符串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;
    }
    以大多数人努力程度之低,根本轮不到去拼天赋~
  • 相关阅读:
    2020软件工程作业05
    一、uart&tty驱动
    柔性数组使用备忘
    指针和数组备忘
    计算信息帧的校验和(备忘)
    Linux系统vim几个常见配置
    C语言实现过滤ASCII在0~127范围内的字符,并去除重复的字符
    extern "C"的用法
    strtol详解
    将一个十进制整数转换为二进制并输出
  • 原文地址:https://www.cnblogs.com/gcter/p/15466957.html
Copyright © 2011-2022 走看看