Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

到底哪里错了,哪位牛人帮忙看下,谢谢!

Posted by a024014 at 2007-08-20 14:08:35 on Problem 1628
/*
我事先对这些演绎进行了排序,排序的准则:一个演绎后面的字符串包含另一个演绎前面的字符串,就把这个演绎放到另一个演绎的前面.
*/
#include <cstdio>
#include <ctype.h>
#include <algorithm>
using namespace std;
struct dtn{
	int fnt[52];
	int bck[52];
};
const int M=256;
dtn ded[M];
int pos;
void change(int a1[],char *str)
{
	memset(a1,0,sizeof(int)*52);
	for(int i=0;str[i];i++)
		if(isupper(str[i]))
			a1[str[i]-'A'+26]=1;
		else a1[str[i]-'a']=1;
}
void retr(char *fir,char *sec){
	memset(ded[pos].fnt,0,sizeof(int)*52);
	for(int i=0;fir[i];i++)
		if(isupper(fir[i]))
			ded[pos].fnt[fir[i]-'A'+26]=ded[pos].bck[fir[i]-'A'+26]=1;
		else ded[pos].fnt[fir[i]-'a']=ded[pos].bck[fir[i]-'a']=1;
	change(ded[pos].bck,sec);
	pos++;
}
bool contain(int a1[],int a2[]){
	for(int i=0;i<52;i++)
		if(a1[i]>=a2[i]);
		else return false;
	return true;
}
void combine(int a1[],int a2[]){
	for(int i=0;i<52;i++)
		a1[i]|=a2[i];
}
bool cmp(dtn x,dtn y){
	return contain(x.bck,y.fnt);
}
int main()
{
	int n,m,i,j;
	int quest[52],ans[52];
	char fir[256],sec[256],cmd[256];
	while(scanf("%d%d",&n,&m)==2){
		pos=0;
		for(i=0;i<n;i++){
			scanf("%s %*s %s",fir,sec);
			retr(fir,sec);
		}
		sort(ded,ded+pos,cmp);
		for(i=1;i<n;i++)
			for(j=0;j<i;j++)
				if(contain(ded[j].bck,ded[i].fnt))
					combine(ded[j].bck,ded[i].bck);
		while(m--){
			scanf("%s",cmd);
			change(quest,cmd);
			memcpy(ans,quest,sizeof(quest));
			for(i=0;i<n;i++){
				if(contain(quest,ded[i].fnt))
					combine(ans,ded[i].bck);
			}
			for(i=0;i<52;i++)
				if(ans[i]) printf("%c",i>25?'A'+(i-26):'a'+i);
			printf("\n");
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator