Advertisement
hemel18681

all words of m length without n sub string in a word

Dec 6th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string s[100];
  5. int m,n;
  6.  
  7. bool strcmp(string a, string b){
  8.     for(int i=0;i<b.length();i++){
  9.         string tmp="";
  10.         for(int j=0;j<a.length();j++){
  11.             tmp.push_back(b[i+j]);
  12.         }
  13.         if(tmp==a){
  14.             return false;
  15.         }
  16.     }
  17.     return true;
  18. }
  19.  
  20. void cheak(int len,int m, string st){
  21.     if(len==m){
  22.         bool flag=true;
  23.         for(int i=0;i<n;i++){
  24.             bool f = strcmp(s[i],st);
  25.             if(f==false){
  26.                 flag=false;
  27.                 break;
  28.             }
  29.         }
  30.         if(flag==false) return;
  31.         else{
  32.             cout<<st<<endl;
  33.             return;
  34.         }
  35.     }
  36.     for(char i='a';i<='z';i++){
  37.         string tmp=st;
  38.         tmp=tmp+i;
  39.         cheak(len+1,m,tmp);
  40.     }
  41. }
  42.  
  43. int main()
  44. {
  45.     cin>>m>>n;
  46.     for(int i=0;i<n;i++){
  47.         cin>>s[i];
  48.     }
  49.     cheak(0,m,"");
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement