Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int A[12];
- int n;
- int find(int a1, int s, int j)
- {
- for (int i=j; i<n; i++)
- {
- if (a1+A[i]==s)
- {
- //cout <<a1<<"+"<<A[i]<<endl;
- return A[i];
- }
- if (a1==s)
- cout<<a1<<"+"<<endl;
- return(a1);
- if (a1+A[i]<s)
- {
- int next = i;//+1;
- if (next <= n)
- return find(a1, A[i], next);
- //cout<<"TEST";
- }
- }
- }
- int main()
- {
- int k;
- cin>>k>>n;
- for (int i=0; i<n; i++)
- cin >>A[i];
- for (int j=0; j<n-1; j++)
- for (int i=0; i<n-1-j; i++)
- if (A[i]<A[i+1])
- swap (A[i], A[i+1]);
- for (int i=0; i<n; i++)
- if (A[i] == k)
- cout<<A[i]<<endl;
- else if(A[i]<k)
- {
- int next = i;//+1;
- if (next <= n)
- cout << find(A[i], k, next);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment