真是那啥的模拟……还是字符串模拟!!!,对于我这个从Pascal转到c++从不用stl的我来说太难了。。。。(那我为啥要转?我也不知道。。。。)
这题个人认为没什么需要转弯的地方,各个方面都考虑到就可以啦。。本人当天比较闲。。用了很多时间写,于是想到哪里就写到哪里,所以代码非常丑,见谅见谅。
附代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
string sayer,ss,youzui,name[100],namee,weiyu,today,feiwu;
char temc1,temc2;
bool mark[1000],panduanfeiren,lier[1000],youmathersser;
int n,m,p,hess,num,len,tem,fanren,tot,feiren;
string day[8]={"ssyou","Monday.","Tuesday.","Wednesday.","Thursday.","Friday.","Saturday.","Sunday."};
struct BIG{
int guilty[1000];
string weather[1000];
int weathercc;
int guiltycc;
};
BIG a[150];
bool check(){
for(int i=1;i<=7;i++)
if(day[i]==youzui)
return true;
return false;
}
bool checkname(){
for(int i=1;i<=n;i++)
if(name[i]==namee)
return true;
return false;
}
int main(){
// freopen("haha.out","w",stdout);
scanf("%d%d%d",&n,&m,&p);
for(int i=1;i<=n;i++)
cin>>name[i];
for(int i=1;i<=n;i++)
name[i]=name[i]+":";
for(int i=1;i<=n;i++)
for(int j=1;j<=500;j++)
a[i].weather[j]=day[0];
for(int i=1;i<=p;i++){
cin>>sayer;
for(int j=1;j<=n;j++)
if(name[j]==sayer)
num=j;
if(num!=0){
scanf("%c",&temc2);
cin>>namee;
if(namee=="I"){
scanf("%c",&temc1);
cin>>weiyu;
if(weiyu=="am"){
scanf("%c",&temc2);
cin>>youzui;
if(youzui=="not"){
scanf("%c",&temc1);
cin>>youzui;
if(youzui=="guilty."){
a[num].guiltycc++;
a[num].guilty[a[num].guiltycc]=-num;
}
}
else
if(youzui=="guilty."){
a[num].guiltycc++;
a[num].guilty[a[num].guiltycc]=num;
}
}
if(weiyu=="is"){
hess=0;
namee=namee+":";
for(int j=1;j<=n;j++)
if(namee==name[j])
hess=j;
if(hess!=0){
scanf("%c",&temc1);
cin>>youzui;
if(youzui=="not"){
scanf("%c",&temc1);
cin>>youzui;
if(youzui=="guilty."){
a[num].guiltycc++;
a[num].guilty[a[num].guiltycc]=-hess;
}
}
else if(youzui=="guilty."){
a[num].guiltycc++;
a[num].guilty[a[num].guiltycc]=hess;
}
}
}
}
if(namee=="Today"){
scanf("%c",&temc1);
cin>>ss;
if(ss=="is"){
scanf("%c",&temc1);
cin>>youzui;
if(check()){
a[num].weathercc++;
a[num].weather[a[num].weathercc]=youzui;
}
}
}
namee=namee+":";
if(checkname()){
for(int j=1;j<=n;j++)
if(namee==name[j])
hess=j;
scanf("%c",&temc1);
cin>>weiyu;
if(weiyu=="is"){
scanf("%c",&temc1);
cin>>youzui;
if(youzui=="not"){
scanf("%c",&temc1);
cin>>youzui;
if(youzui=="guilty."){
a[num].guiltycc++;
a[num].guilty[a[num].guiltycc]=-hess;
}
}
else if(youzui=="guilty."){
a[num].guiltycc++;
a[num].guilty[a[num].guiltycc]=hess;
}
}
}
}
getline(cin,feiwu);
}
/* for(int i=1;i<=n;i++){
for(int j=1;j<=a[i].guiltycc;j++)
printf("%d ",a[i].guilty[j]);
printf("\n");
for(int j=1;j<=a[i].weathercc;j++)
cout<<a[i].weather[j];
printf("\n");
}
*/
for(int i=1;i<=n;i++)
for(int j=1;j<=7;j++){
fanren=i;
today=day[j];
tem=0;
feiren=0;
youmathersser=false;
memset(lier,false,sizeof(lier));
for(int k=1;k<=n;k++){
for(int p=1;p<=a[k].weathercc;p++){
if(a[k].weather[p]!=day[0]&&a[k].weather[p]!=today)
lier[k]=true;
}
for(int p=1;p<=a[k].guiltycc;p++){
if((a[k].guilty[p]>0&&a[k].guilty[p]!=fanren)||(a[k].guilty[p]<0&&a[k].guilty[p]==-fanren))
lier[k]=true;
}
panduanfeiren=true;
for(int p=1;p<=a[k].guiltycc;p++)
if(a[k].guilty[p]!=0)
panduanfeiren=false;
for(int p=1;p<=a[k].weathercc;p++)
if(a[k].weather[p]!="ssyou")
panduanfeiren=false;
if(panduanfeiren)
feiren++;
if(lier[k]==true){
for(int p=1;p<=a[k].guiltycc;p++)
if(a[k].guilty[p]==fanren||(a[k].guilty[p]!=-fanren&&a[k].guilty[p]<0))
youmathersser=true;
for(int p=1;p<=a[k].weathercc;p++)
if(a[k].weather[p]==today)
youmathersser=true;
tem++;
}
}
if(tem<=m&&tem+feiren>=m&&!youmathersser)
mark[i]=true;
}
for(int i=1;i<=n;i++)
if(mark[i])
tot++;
if(tot==0)
printf("Impossible");
if(tot>1)
printf("Cannot Determine");
if(tot==1){
for(int i=1;i<=n;i++)
if(mark[i]){
len=name[i].size();
for(int k=0;k<=name[i].size()-2;k++)
printf("%c",name[i][k]);
}
}
return 0;
}