Будьте добры помочь с данным заданием
Java |
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
| import java.io.*;
public class PNF
{
public static void main(String [] args) throws IOException
{
/*BufferedReader in=new BufferedReader(new InputStreamReader(System.in));*/
String Str;
/*Str=in.readLine();*/
Str="x1x-2Vx-1x3";
System.out.println(Str);
String[] cons;
try
{
cons=Str.split("V");
}
catch(Exception e)
{
System.out.println("ERROR");
return;
}
int max=0;
int c=0;
int i,j,q,p;
char[] tab1;
int tq=1;
int l2=0;
boolean cet=false;
boolean res=false;
j=0;
for(i=0;i<cons.length;i++)
{
String[]st=(cons[i].split("x"));
j++;
l2++;
for(q=1;q<st.length;q++)
{
if(st[q].indexOf('-')!=-1)
{
c=new Integer(st[q].substring(1));
}
else
{
c=new Integer(st[q]);
}
if(max<c)
{
max=c;
}
}
}
for(i=0;i<max;i++)
{
tq=tq*2;
}
boolean[][][]les=new boolean[cons.length][max][2];
boolean[][][]inv=new boolean[cons.length][max][2];
j=0;
for(i=0;i<cons.length;i++)
{
System.out.println("Con "+i);
String[]st=(cons[i].split("x"));
for(q=1;q<st.length;q++)
{
if(st[q].indexOf('-')!=-1)
{
c=new Integer(st[q].substring(1));
}
else
{
c=new Integer(st[q]);
}
for(p=0;p<max;p++)
{
if(c==(1+p))
{les[j][p][0]=true;System.out.println((p+1)+" is in "+(i+1));
if(st[q].indexOf('-')!=-1)
{
les[j][p][1]=true;
System.out.println((p+1)+" inv in "+(i+1));
}
else
{
les[j][p][1]=false;
}
}
else{if(les[j][p][0]!=true){les[j][p][0]=false;}}
}
}
j++;
}
for(q=0;q<max;q++)
{
System.out.print("x"+(q+1)+" ");
}
System.out.print(" f");
System.out.println();
for(i=0;i<tq;i++)
{
char [] ch;
char [] cs=new char[max];
c=max-1;
for(q=0;q<max;q++)
{
cs[q]='0';
}
ch=(Integer.toBinaryString(i)).toCharArray();
for(q=(ch.length-1);q>-1;q--)
{
cs[c]=ch[q];
c--;
}
res=false;
for(q=0;q<l2;q++)
{
cet=true;
for(c=0;c<max;c++)
{
if(les[q][c][0]==true)
{
if(((les[q][c][1]==true)&&(cs[c]=='1'))||((les[q][c][1]==false)&&(cs[c]=='0')))
{
cet=false;
break;
}
}
}
res=res|cet;
}
for(q=0;q<max;q++)
{
System.out.print(cs[q]+" ");
}
if(res==true)
{
System.out.println(" 1");
}
if(res==false)
{
System.out.println(" 0");
}
System.out.println();
}
}
} |
|