题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
#include <iostream> #include <string> #include <map> using namespace std; int main() { string str1; getline(cin, str1); int len = str1.length(); char c; map<char,int> hash; while (cin >> c){ auto it = hash.find(c); if (it == hash.end()){ hash[c] = 1; } } int n = 0, m = 0; for (int i = 0; i < len; i++){ auto it = hash.find(str1[i]); if (it != hash.end()){ //可以找到字符串里的字符 n++; } else{//不能找到 m++; } } if (m == 0){ cout << "true" <<endl; } else{ cout << "false" <<endl; } return 0; } // 64 位输出请用 printf("%lld")