Guest User

Untitled

a guest
Feb 28th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int A[12];
  6. int n;
  7.  
  8. int find(int a1, int s, int j)
  9. {
  10.   for (int i=j; i<n; i++)
  11.   {
  12.     if (a1+A[i]==s)
  13.     {
  14.      //cout <<a1<<"+"<<A[i]<<endl;
  15.      return A[i];
  16.     }
  17.      
  18.     if (a1==s)
  19.      cout<<a1<<"+"<<endl;
  20.      return(a1);
  21.      
  22.     if (a1+A[i]<s)
  23.     {
  24.       int next = i;//+1;
  25.       if (next <= n)
  26.         return find(a1, A[i], next);
  27.        
  28.       //cout<<"TEST";
  29.     }
  30.   }
  31. }
  32.  
  33. int main()
  34. {
  35.     int k;
  36.     cin>>k>>n;
  37.     for (int i=0; i<n; i++)
  38.       cin >>A[i];
  39.        
  40.     for (int j=0; j<n-1; j++)
  41.       for (int i=0; i<n-1-j; i++)
  42.         if (A[i]<A[i+1])
  43.           swap (A[i], A[i+1]);
  44.          
  45.     for (int i=0; i<n; i++)
  46.       if (A[i] == k)
  47.         cout<<A[i]<<endl;
  48.       else if(A[i]<k)
  49.       {
  50.         int next = i;//+1;
  51.         if (next <= n)
  52.           cout << find(A[i], k, next);
  53.       }
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment