zoukankan      html  css  js  c++  java
  • 7615. 9.10 Anagrams

    Description

    Rewrite Exercise 7.18 using the string class with the following function header:

    bool isAnagram(const string &s1, const string &s2)

    Two words are anagrams if they contain the same letters in any order.

    自己班的作业写到烦了又跑去蹭别人班的题做……因为这是道改编题,不知道原题的要求是什么,纠结了很久=。=这里的anagram的要求应该是两个字符串具有相同的字符,每种字符的数目一样,总之就就有字符顺序不同而已,大小写还是敏感的,匹配范围也包括非字母

    一开始试的时候又是去重又是去大小写敏感又是去非字母字符,都WA,后来试了一下multiset,经过N种组合后发现什么都不去的写法居然过了,然后换了set发现又WA,才明白不需要去重的....试到最后发现只要分别排个序对比一下就行了,好水……

    #include<string>
    #include<algorithm>
    using namespace std;
    
    bool isAnagram( const string &s1, const string &s2 )
    {
        string a = s1, b = s2;
        
        sort( a.begin(), a.end() );
        sort( b.begin(), b.end() );
        
        return a == b;
    }
  • 相关阅读:
    PCI总线原理(二)
    smbus协议
    PCI总线原理(一)
    计算机术语中关于 Assert 和Deassert 词汇意思
    用安全存储器实现FPGA的身份识别及防拷贝
    主板结构
    qt 雅黑字体
    PCIExpress总线简介
    PHY管理接口(MDIO)
    PCI总线原理(三)
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2963785.html
Copyright © 2011-2022 走看看