哪位大佬路过?快来看看

周鸿博 2020-05-23 21:56:42

最近代码总是写不对...... 1.5.4.2 有谁能找一下代码错在哪吗?

#include <bits/stdc++.h>
using namespace std;

char ch[20][20]=
{
	"I am guilty.",
	"I am not guilty.",
	"Today is Monday.",
	"Today is Tuesday.",
	"Today is Wednesday.",
	"Today is Thursday.",
	"Today is Friday.",
	"Today is Saturday.",
	"Today is Sunday.",
};

char ch2[10][20]=
{
	"is guilty.",
	"is not guilty.",
};

int sum,guilty[30][30];
int day[30][9];
int n,m,p;
char name[30][500],s[10001],ans[300];
int zhen[40],jia[40];

void update()
{
	int len=strlen(s),cnt=0,cnt2=0;
	int lena;
	int ren=0,ren2=0;
	char t[30],name2[300];
	memset(t,0,sizeof(t));
	memset(name2,0,sizeof(name2));
	for(int i=0; i<len; i++)
	{
		if(s[i]==':')
		{
			lena=i-1;
			break;
		}
		else
		{
			name2[cnt2++]=s[i];
		}
	}
	for(int i=1; i<=m; i++)
	{
		int lenb=strlen(name[i]),flag=0;
		if(lenb!=lena+1)
		{
			continue;
		}
		else
		{
			if(!strcmp(name2,name[i]))
			{
				ren=i;
				break;
			}
		}
	}
	if(!ren)
	{
		return;
	}
	for(int i=lena+3; i<len; i++)
	{
		if(s[i]!='\r')
		{
			t[cnt++]=s[i];
		}
	}
	int ff=0;
	for(int i=0; i<=8; i++)
	{
		if(!strcmp(t,ch[i]))
		{
			ff=1;
			if(i==0)
			{
				guilty[ren][ren]=1;
			}
			else if(i==1)
			{
				guilty[ren][ren]=2;
			}
			else
			{
				day[ren][i-1]=1;
			}
			break;
		}
	}
	if(!ff)
	{
		int lenx;
		char t2[300],coc=0,t3[20],tot=0;
		memset(t2,0,sizeof(t2));
		memset(t3,0,sizeof(t3));
		for(int i=0; i<strlen(t); i++)
		{
			if(t[i]==' ')
			{
				lenx=i-1;
				break;
			}
			else
			{
				t2[coc++]=t[i];
			}
		}
		for(int i=1; i<=m; i++)
		{
			if(lenx+1!=strlen(name[i]))
			{
				continue;
			}
			else if(!strcmp(t2,name[i]))
			{
				ren2=i;
				break;
			}
		}
		if(!ren2)
		{
			return;
		}
		for(int i=lenx+2; i<strlen(t); i++)
		{
			if(t[i]!='\r')
			{
				t3[tot++]=t[i];
			}
		}
		for(int i=0; i<2; i++)
		{
			if(!strcmp(t3,ch2[i]))
			{
				if(i==0)
				{
					guilty[ren][ren2]=1;
				}
				else
				{
					guilty[ren][ren2]=2;
				}
				break;
			}
		}
		memset(t2,0,sizeof(t2));
		memset(t3,0,sizeof(t3));
	}
}

int check(int peo,int today)
{
	memset(jia,0,sizeof(jia));
	int fake=0;
	int zero=0;
	for(int i=1; i<=m; i++)
	{
		int g=0,gg=0;
		if(guilty[i][peo]==2)
		{
			jia[i]=1;
		}
		if(guilty[i][peo]==1)
		{
			zhen[i]=1;
		}
		if(jia[i])
		{
			continue;
		}
		for(int j=1; j<=m; j++)
		{
			if(guilty[i][j]==1&&j!=peo)
			{
				jia[i]=1;
				break;
			}
		}
		for(int j=1; j<=m; j++)
		{
			if(guilty[i][j]==2&&j!=peo)
			{
				zhen[i]=1;
				break;
			}
		}
		if(jia[i])
		{
			continue;
		}
		for(int j=1; j<=7; j++)
		{
			if(day[i][j]==1&&j!=today)
			{
				jia[i]=1;
				break;
			}
		}
		for(int j=1; j<=m; j++)
		{
			if(guilty[i][j]==1||guilty[i][j]==2)
			{
				g=1;
				break;
			}
		}
		for(int j=1; j<=7; j++)
		{
			if(day[i][j]==1)
			{
				gg=1;
				break;
			}
		}
		if(zhen[i]==1&&jia[i]==1)
		{
			return 0;
		}
		if(!gg&&!g)
		{
			zero++;
		}
	}
	for(int i=1; i<=m; i++)
	{
		if(jia[i])
		{
			fake++;
		}
	}
	for(int i=0; i<=zero; i++)
	{
		if(fake+i==n)
		{
			return 1;
		}
	}
	return 0;
}

int tot1=0,cocc=0;
int ans2[40];

int main()
{
	cin>>m>>n>>p;
	for(int i=1; i<=m; i++)
	{
		cin>>name[i];
	}
	char ch=getchar();
	while(ch==10)
	{
		ch=getchar();
	}
	getchar();
	for(int i=1; i<=p; i++)
	{
		gets(s);
		update();
	}
	for(int i=1; i<=m; i++)
	{
		for(int j=1; j<=7; j++)
		{
			if(check(i,j))
			{
				if(tot1>1&&i!=ans2[cocc])
				{
					cout<<"Cannot Determine";
					return 0;
				}
				if(i!=ans2[cocc])
				{
					tot1++;
					strcpy(ans,name[i]);
					cocc++;
					ans2[cocc]=i;
				}
			}
		}
	}
	if(!tot1)
	{
		cout<<"Impossible";
	}
	else
	{
		cout<<ans;
	}
	return 0;
}

谢谢

共 1 条回复

廖梓旭 X

?