Advertisement
kburnik

C++ - Zadatak Combo - rješenje

Jan 10th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. /*
  2.     Zadatak: Kombiniraj
  3.         Ispisati sve rijeci koje se sastoje od slova iz rijeci R, a leksikografski
  4.         su nakon rijeci A te prije rijeci B (ukljucivo).
  5.         rijec moze imati do 8 znakova i svi su jedinstveni
  6.        
  7.     Složenost: Faktorijelna, uz optimizaciju
  8.  
  9.     Primjeri:
  10.  
  11.     Datum: 2012-05-04
  12.  
  13.     Autor: Kristijan Burnik, udruga informatičara Božo Težak
  14.  
  15.     Gmail: kristijanburnik
  16.  
  17. */
  18. #include <iostream>
  19. #include <algorithm>
  20. #include <set>
  21. using namespace std;
  22.  
  23. bool between(string from, string c, string to) {
  24.     return from <= c && c <= to;
  25. }
  26.  
  27. void permutiraj(string a, string b,string &from,string &to) {
  28.     if (b.size() == 0) {
  29.         cout << a << endl;
  30.     } else {
  31.         for (int i = 0; i < b.size(); i++) {
  32.             string l = a + b.substr(i,1);
  33.             if (between( from.substr(0,l.size()) , l , to.substr(0,l.size() ) ) )
  34.               permutiraj( l,  b.substr(0,i) + b.substr(i+1), from, to);
  35.         }
  36.     }
  37. }
  38.  
  39. int main() {
  40.    
  41.     string a,from,to;
  42.    
  43.     cin >> a >> from >> to;
  44.     a = a.substr(0,8);
  45.    
  46.     permutiraj("",a,from,to);
  47.    
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement