20pts求调
查看原帖
20pts求调
1111314
KiPPer_1215楼主2023/11/16 08:49
#include<bits/stdc++.h>
using namespace std;
int m,n,p,ans=0;
string name[21],a;
string day[10]{
	"Today is Sunday.",
	"Today is Monday.",
	"Today is Tuesday.",
	"Today is Wednesday.",
	"Today is Thursday.",
	"Today is Friday.",
	"Today is Saturday.",
};
struct zhengci{
	int id;
	string s;
}zc[105]; 
map<string,int>mp; 
int jud(zhengci x,int gl,int date){
	if(x.s=="I am guilty."){
		if (x.id==gl) return 1;
		return -1;
	}
	if(x.s=="I am not guilty."){
		if (x.id==gl) return -1;
		return 1;
	}
	if(x.s.find(" is guilty.")!=-1){
		if(x.s.erase(x.s.find(" is guilty."),11)==name[gl]) return 1;
		return -1;
	}
	if(x.s.find(" is not guilty.")!=-1){
		if(x.s.erase(x.s.find(" is not guilty."),15)==name[gl]) return -1;
		return 1;
	}
	if(x.s.find("Today is ")!=-1) {
		if(x.s==day[date]) return 1;
		return -1;
	}
	return 0;
} //判断每句证词的正误 
bool func(int g,int e){
	int f=0,tf[21];
	for(int k=1;k<=p;k++){
		if(jud(zc[k],g,e)==0) continue;
		else if(tf[zc[k].id]==0){
			if(jud(zc[k],g,e)==1) tf[zc[k].id]=1;
			if(jud(zc[k],g,e)==-1) tf[zc[k].id]=-1,f++; 
		}
		else if(tf[zc[k].id]!=jud(zc[k],g,e)) return false; 
	}
	if(f==n) return true;
	return false; 
}
int main() {
	cin>>m>>n>>p;
	for(int i=1; i<=m; i++) {
		cin>>name[i];
		mp[name[i]]=i;
	}
	name[0]="Impossible"; 
	for(int i=1; i<=p; i++) {
		cin>>a;
		a.erase(a.size()-1,1);//冒号 
		zc[i].id=mp[a];
		getline(cin,a);
		a.erase(0,1); //证词前空格 
		if(a[a.length()-1]=='\n'||a[a.length()-1]=='\r')	//换行符 
			a.erase(a.length()-1,1);
		zc[i].s=a;
	}
	for(int i=1;i<=m;i++)
    for(int j=0;j<7;j++){
    	if(func(i,j)==true&&ans==0) {
    		ans=i;
    		break;
		}
		else if(func(i,j)==true) {
			cout<<"Cannot Determine";
			return 0;
		}
	}
	cout<<name[ans];
	return 0;
}//P1039
2023/11/16 08:49
加载中...