1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <iostream> #include <sstream> #include <stdio.h> #include <string> #include <vector>
using std::string; using std::stringstream; using std::vector;
class Solution { public: int canBeTypedWords(string text, string brokenLetters) { stringstream ss(text); string token; vector<string> words; int broken = 0; while (std::getline(ss, token, ' ')) { words.push_back(token); } for (string word : words) { for (char ch : brokenLetters) { if (word.find(ch) != string::npos) { broken++; break; } } } return words.size() - broken; } };
int main() { Solution s; int res = s.canBeTypedWords(string("hello world"), string("ad")); printf("%d\n", res); }
|