Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zadatak: Kombiniraj
- Ispisati sve rijeci koje se sastoje od slova iz rijeci R, a leksikografski
- su nakon rijeci A te prije rijeci B (ukljucivo).
- rijec moze imati do 8 znakova i svi su jedinstveni
- Složenost: Faktorijelna, uz optimizaciju
- Primjeri:
- Datum: 2012-05-04
- Autor: Kristijan Burnik, udruga informatičara Božo Težak
- Gmail: kristijanburnik
- */
- #include <iostream>
- #include <algorithm>
- #include <set>
- using namespace std;
- bool between(string from, string c, string to) {
- return from <= c && c <= to;
- }
- void permutiraj(string a, string b,string &from,string &to) {
- if (b.size() == 0) {
- cout << a << endl;
- } else {
- for (int i = 0; i < b.size(); i++) {
- string l = a + b.substr(i,1);
- if (between( from.substr(0,l.size()) , l , to.substr(0,l.size() ) ) )
- permutiraj( l, b.substr(0,i) + b.substr(i+1), from, to);
- }
- }
- }
- int main() {
- string a,from,to;
- cin >> a >> from >> to;
- a = a.substr(0,8);
- permutiraj("",a,from,to);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement