Skip to content

Commit

Permalink
[cpp] boj14426.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
junhochoi-dev committed Jul 14, 2023
1 parent 93b299a commit 922f9fa
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cjh970422/boj14426/boj14426.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(k, sz) for(int k = 0; k < sz; k++)
#define endl '\n'

class Node{
public:
char alphabet;
Node* next[26];
};
int N, M;
vector<string> wordlist;
vector<string> checklist;
int main() {
fastio
cin >> N >> M;
loop(n, N){
string tmp;
cin >> tmp;
wordlist.push_back(tmp);
}
loop(m, M){
string tmp;
cin >> tmp;
checklist.push_back(tmp);
}
Node* headnode = new Node();
loop(n, N){
string str = wordlist[n];
Node* currNode = headnode;
loop(m, str.length()){
char currc = str[m];
int num = currc - 'a';
if(currNode->next[num] == NULL) currNode->next[num] = new Node();
currNode = currNode->next[num];
}
}
int includeString = 0;
loop(n, M){
string str = checklist[n];
Node* currNode = headnode;
bool existCheck = true;
loop(m, str.length()){
char currc = str[m];
int num = currc - 'a';
if(currNode->next[num] == NULL) {
existCheck = false;
break;
}
currNode = currNode->next[num];
}
if(existCheck) includeString++;
}
cout << includeString << endl;
return 0;
}

0 comments on commit 922f9fa

Please sign in to comment.