counting-words-with-a-given-prefix 1.0.0
Counting Words With a Given Prefix
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <bits/stdc++.h>
2
3using namespace std;
4
6{
7public:
8 int prefixCount(vector<string>& words, string pref)
9 {
10 int count = 0;
11 for (string& word: words)
12 {
13 for (int i = 0; i < (int)pref.size(); ++i)
14 {
15 if (pref[i] != word[i])
16 break;
17 else
18 if (i + 1 == (int)pref.size())
19 count++;
20 }
21 }
22 return count;
23 }
24};
25
26int main()
27{
28 vector<string> words = {"pay","attention","practice","attend"};
29 string prefix = "at";
30 cout << "output: " << Solution().prefixCount(words, prefix) << endl;
31 return 0;
32}
int prefixCount(vector< string > &words, string pref)
Definition main.cpp:8
int main()
Definition main.cpp:26