Advertisement
LukacikPavel

obdlznik

Nov 11th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void vypis(int a[], int k){
  5.     int sucet=k;
  6.     int sucet2=0;
  7.     for (int z = 0; z<k; z++){
  8.         cout << a[z];
  9.     }
  10.     cout<<endl;
  11. }
  12.  
  13. void generuj(int a[], int i, int k, int sucet){
  14.     /* v poli a dlzky k mame prvych i cifier,
  15.      * chceme vygenerovat vsetky moznosti
  16.      * poslednych k-i cifier */
  17.     if (sucet == k)
  18.     {
  19.         vypis(a, i);
  20.     } else if(sucet > k){
  21.         return;
  22.     } else {
  23.         for (int x = 1; x < 3; x++)
  24.         {
  25.             a[i] = x;
  26.             sucet += x;
  27.             //cout<<"sucetPred "<<sucet<<endl;
  28.             generuj(a, i + 1, k, sucet);
  29.             sucet -= x;
  30.             //cout<<"sucetPo "<<sucet<<endl;
  31.         }
  32.     }
  33. }
  34.  
  35. int main() {
  36.     const int maxK = 100;
  37.     int a[maxK];
  38.     int  k;
  39.     cin  >> k;
  40.     generuj(a, 0, k, 0);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement