Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string palavra, alfa;
- int cont, k;
- struct node{
- bool end;
- struct node* word[30];
- } *head;
- string nova(int x){
- string new_= "";
- for(int i = x; i < palavra.size(); i++) new_ += palavra[i];
- return new_;
- }
- void init(){
- head = new node();
- head->end = false;
- }
- void add(string palavra){
- node* current = head;
- int aux = 0;
- for(int i = 0; i < palavra.size(); i++){
- int letra = palavra[i] - (int)'a';
- if(alfa[letra] == '0') aux++;
- if(aux > k) return;
- if(current->word[letra] == NULL) current->word[letra] = new node();
- current = current->word[letra];
- if(!current->end) cont++;
- current->end = true;
- }
- }
- int main(){
- ios::sync_with_stdio(false);
- cin >> palavra >> alfa >> k;
- cont = 0;
- init();
- for(int i = 0; i < palavra.size(); i++){
- add(nova(i));
- }
- cout << cont << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement