热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

判断集合关系(自反,反自反,对称,反对称,传递)

具体代码如下1#include2usingnamespacestd;34voidInput(inta[25][2],ints)5{6inti;78for(i0;

具体代码如下

1 #include
2 using namespace std;
3
4 void Input(int a[25][2],int s)
5 {
6 int i;
7
8 for (i = 0; i )
9 {
10 cin >> a[i][0] >> a[i][1];
11 }
12 }
13
14 void Output(int a[5][2],int b[5][5], int n,int s)
15 {
16 int i;
17 int j, k;
18 int buff=0;
19 int buff1, buff2;
20 cout <"the relation is :" << endl;
21 for (i &#61; 0; i )
22 {
23 buff1 &#61; a[i][0] - 1;
24 buff2 &#61; a[i][1] - 1;
25 b[buff1][buff2] &#61; 1;
26 }
27 for (j &#61; 0; j )
28 {
29 for (k &#61; 0; k )
30 {
31 cout <" ";
32 buff&#43;&#43;;
33 if (buff%n &#61;&#61; 0)
34 cout << endl;
35 }
36 }
37 cout << endl;
38 }
39 void IsReflexive(int b[5][5],int n)
40 {
41 int i;
42 cout <<"1、Is Reflexive?" <endl;
43 for (i &#61; 0; i )
44 {
45 if (!b[i][i])
46 {
47 cout <<"the answer is NO!" << endl;
48 cout <<"At least can&#39;t find" <<"<" <1 <<"," <1 <<">" <endl;
49 return;
50 }
51 }
52 cout <<"the answer is YES!" <endl;
53 }
54 void IsAntireflexive(int b[5][5], int n)
55 {
56 int i;
57 cout <<"2、Is Antireflexive?" <endl;
58 for (i &#61; 0; i )
59 {
60 if (b[i][i])
61 {
62
63 cout <<"the answer is NO!" << endl;
64 cout <<"At least find" <<"<" <1 <<"," <1 <<">" <endl;
65 return;
66 }
67 }
68 cout <<"the answer is YES!" <endl;
69 }
70 void IsSymmetric(int b[5][5], int n)
71 {
72 int i, j;
73 cout <<"3、Is Symmetric?" < endl;
74 for (i &#61; 0; i )
75 {
76 for (j &#61; 0; j )
77 {
78 if (b[i][j] !&#61; b[j][i])
79 {
80 cout <<"the answer is NO!" << endl;
81 cout <<"At least both of" <<"<" <1 <<"," <1 <<">" <<"and" <<"<" <1 <<"," <1 <<">" <<"not appear together" < endl;
82 return;
83 }
84 }
85
86 }
87 cout <<"the answer is YES!" < endl;
88 }
89 void IsAntisymmetry(int b[5][5], int n)
90 {
91 int i, j;
92 cout <<"4、Is Antisymmetry?" < endl;
93 for (i &#61; 0; i )
94 {
95 for (j &#61; 0; j )
96 {
97 if (b[i][j] && b[i][j] &#61;&#61; b[j][i] && i !&#61; j)
98 {
99 cout <<"the answer is NO!" << endl;
100 cout <<"At least both of" <<"<" <1 <<"," <1 <<">" <<"and" <<"<" <1 <<"," <1 <<">" <<"appear together" < endl;
101 return;
102 }
103 }
104 }
105 cout <<"the answer is YES!" < endl;
106 }
107 void IsTransmit(int b[5][5], int n)
108 {
109 int i, j, k;
110 cout <<"5、Is Transmit?" < endl;
111 for (i &#61; 0; i )
112 {
113 for (j &#61; 0; j )
114 {
115 for (k &#61; 0; k )
116 {
117 if (b[i][j] && b[j][k]&&!b[i][k])
118 {
119
120 cout <<"the answer is NO!" << endl;
121 cout <<"At lease can&#39;t find" <<"<" <1 <<"," <1 <<">" < endl;
122 return;
123
124 }
125
126 }
127 }
128 }
129 cout <<"the answer is YES!" < endl;
130 }
131 int main()
132 {
133 int In[25][2];
134 int Pu[5][5] &#61; {0};
135 int n ;
136
137 cout <<"input number of the element(0<&#61;n<&#61;5)" <//输入元素个数
138
139 cin >> n;
140 for (int l &#61; 0; l )
141 {
142 cout <1 <<" ";
143
144 }
145 cout << endl;
146 while (n <0||n>5)
147 {
148 cout <<"error!" << endl;
149 cin >> n;
150 }
151 int s;
152 cout <<"input a number of relation" <//输入序偶个数
153 cin >> s;
154 cout <<"input the relation" << endl;
155 Input(In, s);
156 Output(In,Pu, n,s);
157 IsReflexive(Pu, n);
158 IsAntireflexive(Pu,n);
159 IsSymmetric(Pu, n);
160 IsAntisymmetry(Pu, n);
161 IsTransmit(Pu, n);
162 system("pause");
163 return 0;
164
165 }

 

转:https://www.cnblogs.com/zlgxzswjy/p/4908390.html



推荐阅读
author-avatar
1凡evan
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有