Advertisement
Manioc

271D

Feb 6th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string palavra, alfa;
  6.  
  7. int cont, k;
  8.  
  9. struct node{
  10.     bool end;
  11.     struct node* word[30];
  12. } *head;
  13.  
  14. string nova(int x){
  15.     string new_= "";
  16.     for(int i = x; i < palavra.size(); i++) new_ += palavra[i];
  17.    
  18.     return new_;
  19. }
  20.  
  21. void init(){
  22.     head = new node();
  23.     head->end = false;
  24. }
  25. void add(string palavra){
  26.     node* current = head;
  27.     int aux = 0;
  28.    
  29.     for(int i = 0; i < palavra.size(); i++){
  30.         int letra = palavra[i] - (int)'a';
  31.        
  32.         if(alfa[letra] == '0') aux++;
  33.         if(aux > k) return;
  34.        
  35.         if(current->word[letra] == NULL) current->word[letra] = new node();
  36.         current = current->word[letra];
  37.    
  38.         if(!current->end) cont++;
  39.         current->end = true;
  40.     }
  41. }
  42.  
  43. int main(){
  44.     ios::sync_with_stdio(false);
  45.     cin >> palavra >> alfa >> k;
  46.    
  47.     cont = 0;
  48.     init();
  49.     for(int i = 0; i < palavra.size(); i++){
  50.         add(nova(i));
  51.     }
  52.     cout << cont << endl;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement