poj 1628 Deduction 模拟

题意:

给一些蕴含式和一个为真的语句集合,求总共能推导出的语句集合。

分析:

维护一个里面语句都为真的集合就好。ps,这水题居然只有一百多人做出来。。

代码:

//poj 1628
//sep9
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
set<char> s1[256],s2[256],s;
set<char>::iterator iter;

bool f(char c){
	if((c<='z'&&c>='a')||(c<='Z'&&c>='A'))
		return true;
	return false;
}

void print(set<char> s)
{
	for(char i='a';i<='z';++i)
		if(s.count(i)>0)
			printf("%c",i);
	for(char i='A';i<='Z';++i)
		if(s.count(i)>0)
			printf("%c",i);
	printf("\n");	
}

void scan(set<char> &s)
{
	s.clear();
	char ch;
	while((ch=getchar())&&!f(ch));
	s.insert(ch);	
	while((ch=getchar())&&f(ch)){
		if(s.count(ch)==0)
			s.insert(ch);
	}
}

bool subset_of_s(int i){
	for(iter=s1[i].begin();iter!=s1[i].end();++iter){
		if(s.count(*iter)==0)
			return false;
	}
	return true;
}

int main()
{
	int i,m,n;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;++i){
		scan(s1[i]);		
		scan(s2[i]);
	}
	while(n--){
		scan(s);
		bool update;
		while(1){
			update=false;
			for(i=0;i<m;++i)
				if(subset_of_s(i))	
					for(iter=s2[i].begin();iter!=s2[i].end();++iter)
						if(s.count(*iter)==0){
							s.insert(*iter);
							update=true;
						}
			if(update==false)
				break;
		}	
		print(s);		
	}
	return 0;	
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值