-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ10.cpp
More file actions
126 lines (103 loc) · 2.78 KB
/
Q10.cpp
File metadata and controls
126 lines (103 loc) · 2.78 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using namespace std;
#include <iostream>
#include <vector>
void remove_bad_vertex( int **adj, int n) {
/*
Objective: To remove a vertex known as bad vertex if it
has less than 5 known or less than 5 unknown people.
Input Variables:
int **adj : is an adjacency matrix
A '1' in adjancency matrix shows that ith person is
known to jth person.
int n : Number of Potential Invitees
Approach :
if count < 5 || count > n-5:
then that particular person should be excluded from the guest list.
*/
int count;
for ( int i = 1 ; i<=n; i++ ){
count = 0;
for (int j = 1; j <= n; j++ ) {
if ( adj[i][j] == 1)
count++;
}
if ( count < 5 || count > n - 5 ){
for ( int j = 1; j <= n; j++)
if ( adj[j][i] == 1 )
adj[j][i] = 0;
}
}
}
void display(int **adj, int n) {
/*
Objective : To Display Whom are going to be invited for the party by the Alice
Input Variable:
int **adj : is an adjacency matrix
A '1' in adjancency matrix shows that ith person is
known to jth person.
int n : Number of Potential Invitees
Approach : Each person who has count >= 5 will be shown in the list.
*/
int count;
cout << "------------------People Invited are---------------------";
cout << "\n Person \t No of Known People \t Known People ";
for ( int i = 1; i <= n; i++ ) {
count = 0;
for ( int j = 1; j <= n; j++ )
if ( adj[i][j] == 1)
count++;
if ( count >= 5 ) {
cout << "\n "<< i <<" \t " << count <<" \t ";
for ( int j = 1; j <= n; j++ )
if ( adj[i][j] == 1)
cout << j << " ";
}
}
}
int main() {
/*
Objective: To find who can be invited for the party
User Variable:
int n: Number of Potential Invitees
int **adj: is an adjacency matrix
A '1' in adjancency matrix shows that ith person is
known to jth person.
Approach:
solved by using remove_bad_vertex().
*/
int n;
cout << "\n Enter No of potential invitees in the party : ";
cin >> n;
if ( n < 11 ) {
while ( true ) {
cout << "\n Potential Invitees should be greater than 11 ";
cout << "\n Again Enter Potential No of Invitees : ";
cin >> n;
if ( n >= 11 )
break;
}
}
int **adj;
adj = new int *[n+1];
for( int i=0; i <=n ; i++ )
adj[i] = new int[n+1];
for ( int i = 1; i <=n; i++) {
for ( int j=1; j<=n ; j++)
adj[i][j] = 0;
}
for ( int i = 1; i <= n; i++ ) {
int known;
int N;
cout << "\n Enter no of people known by person"<<i<<" : ";
cin >> N;
for ( int j = 1; j <= N; j++ ) {
cout << "\n Known Person "<<j<<" : ";
cin >> known;
adj[i][known]= 1;
}
}
remove_bad_vertex(adj,n);
display(adj,n);
cout << endl;
return 0;
}