Advertisement
Mlack

digits2

Dec 26th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. void opp2(int L, int K);
  8. void opp05 (int L, int K);
  9.  
  10. stack<int> num;
  11.  
  12. int main()
  13. {
  14.         int L, K;
  15.         cin >> L >> K;
  16.         L *= 2;
  17.        
  18.         vector<int> array (1);
  19.        
  20.         opp2(L, K);
  21.         opp05(L, K);
  22.        
  23.         int counter = 0;
  24.         int temp;
  25.         int flag;
  26.        
  27.         array[0] = num.top();
  28.         num.pop();
  29.        
  30.         while (!num.empty())
  31.         {
  32.                 counter++;
  33.                
  34.                 do
  35.                 {
  36.                         temp = num.top();
  37.                         num.pop();
  38.                         flag = 0;
  39.                
  40.                         for (int j = 0; j < counter; j++)
  41.                         {
  42.                                 if (temp == array[j])
  43.                                 {
  44.                                         flag = 1;
  45.                                         break;
  46.                                 }
  47.                                
  48.                                 if (j == counter - 1)
  49.                                         array[counter] = temp;
  50.                         }
  51.                 } while (flag == 1);
  52.         }
  53.        
  54.         cout << counter + 1;
  55.        
  56.        
  57.         return 0;
  58. }
  59.  
  60. void opp2(int L, int K)
  61. {
  62.         L /= 2;
  63.         if (K == 1)
  64.                 num.push(L);
  65.         else
  66.         {
  67.                 if (L % 2 != 1)
  68.                         opp2(L, K - 1);
  69.                
  70.                 opp05(L, K - 1);
  71.         }
  72. }
  73. void opp05 (int L, int K)
  74. {
  75.         L--;
  76.         if (K == 1)
  77.                 num.push(L);
  78.         else
  79.         {
  80.                 if (L % 2 != 1)
  81.                         opp2(L, K - 1);
  82.                
  83.                 opp05(L, K - 1);
  84.         }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement