题解 | #字符串字符匹配#

字符串字符匹配

http://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93

注意set本身就是去重,而且自动升序排序,unordered_set没有顺序,也是去重的。

#include <algorithm>
#include <set>

using namespace std;

int main() {
    string shorts,longs;
    while(cin>>shorts>>longs){
        bool has=true;
      set<char> cset;
        for(auto c:longs){
            cset.insert(c);
        }
        for(auto a:shorts){
            if(!cset.count(a)) 
            {has = false; break;}
        }
        cout<<boolalpha<<has;
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务