题解 | 字符串字符匹配

字符串字符匹配

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

#include<bits/stdc++.h>
using namespace std;
char s[210],t[210];
int a[26];//用于统计t数组中字母出现情况
int main(){
      scanf("%s%s",s,t);
      int len=strlen(t);
      for(int i=0;i<len;i++){
        if(!a[t[i]-97])a[t[i]-97]++;
      }//统计t数组中字母出现情况
      len=strlen(s);
      bool p=true;
      for(int i=0;i<len;i++){
         //如果s数组中有t数组中没有的字母,说明错误
           if(!a[s[i]-97]){p=false;break;}
      }
      if(p)cout<<"true";
      else cout<<"false";
return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务