/*
先把所有可简化的字符串写出来 比如!!简化为没有 (V)简化成V 然后每读一个非空格字符 都扫描一次其后缀是否是可化简的字符串 是就化简 读到EOF或者\n就输出整个字符串就好 显然合法的输入一定可以化简成F或V
有个坑点是最后一个输入似乎结尾是EOF不是\n
*/
/*
采用的是枚举法;先枚举所有的可能性,再来一一匹配,并简化;最后只有一个值;
*/
#include<stdio.h>
#include<string.h>
int i,j,q,z,k,w=1;
char c,a[105],s[13][2][4]={"(V)","V","(F)","F","!!","","!V","F","!F","V","V|V","V","V&V","V","F|F","F","F&F","F","V|F","V","V&F","F","F|V","V","F&V","F"};
int main()
{
while (scanf("%c",&c)!= EOF){
i=0;
if (c!=32)
a[i++]=c;
while (scanf("%c",&c)!=EOF&& c!=10){
if (c!=32)
a[i++]=c;
for (j=0;j<13;j++){
q=strlen(s[j][0]),k = 0;
while (a[i-q+k]==s[j][0][k])
k++;
if (k>=q)
strcpy(a+i-q,s[j][1]),i+=strlen(s[j][1])-q;
}
}
printf("Expression %d: %s\n",w++,a);
}}
POJ 2106(转载POJ discuss)
最新推荐文章于 2018-09-18 13:45:38 发布