-
Notifications
You must be signed in to change notification settings - Fork 0
/
IwonLotto2.cpp
34 lines (32 loc) · 923 Bytes
/
IwonLotto2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
int main()
{
int n,s,a[100];
unordered_map <int,vector <int>> triplet;
cout << "Enter n,s ";
cin>>n>>s;
cout<<"Enter array"<<endl;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
triplet[a[i]+a[j]+a[k]]={i,j,k};
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
{
int temp=s-a[i]-a[j]-a[k];
if(triplet.find(temp)!=triplet.end())
{
vector <int> v= triplet[temp];
cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<a[v[0]]<<" "<<a[v[1]]<<" "<<a[v[2]];
return 0;
}
}
cout<<"Not Possible";
return 0;
}