-
Notifications
You must be signed in to change notification settings - Fork 2
/
1.cpp
86 lines (81 loc) · 1.81 KB
/
1.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<bits/stdc++.h>
using namespace std;
map<int,vector<int> >graph;
int n,m,number;
vector<int>ans_size;
map<int,int>check;
bool flag=false;
int halls_algo(int level)
{
//cout<<"Level = "<<level<<" ans_size = "<<ans_size.size()<<endl;
if(ans_size.size()==3)
{
cout<<"Found Match\n";
for(int i=0; i<ans_size.size(); i++)
{
cout<<"For "<<char(i+65)<<" : "<<ans_size[i]<<endl;
}
flag=true;
ans_size.clear();
cout<<endl;
}
else
{
for(int j=0; j<graph[level].size(); j++)
{
int value=graph[level][j];
if(!check[value])
{
//cout<<"level "<<level<<" and value = "<<value<<endl;
check[value]=1;
ans_size.push_back(value);
halls_algo(level+1);
//cout<<"back to the level = "<<level<<endl;
check[value]=0;
if(ans_size.size()!=0)
ans_size.pop_back();
}
}
}
}
int main()
{
cout<<"how many girls ?";
cin>>n;
cout<<"enter the connected boys for ";
for(int i=1; i<=n; i++)
{
cout<<i<<": ";
cout<<"enter connected boys and press (-1) to stop \n";
while(1)
{
// scanf("%c",&ch);
cin>>number;
if(number==-1)
{
break;
}
else
{
graph[i].push_back(number);
}
}
}
//
// for(int i=1; i<=n; i++)
// {
// cout<<" for "<<i<<": ";
//
// for(int j=0; j<graph[i].size(); j++)
// {
// cout<<graph[i][j]<<" ";
// }
// cout<<endl;
// }
halls_algo(1);
if(!flag)
{
cout<<"No pattern Found";
}
return 0;
}