indent #include <bits/stdc++.h>
#define elif else if
#include
using namespace std;
bool E = false;
const int N = 1001;
struct cs//陈述句
{
string zhu = “”;
string bin = “”;
string wei = “”;
bool f = false;
bool s = false;
bool j = false;
};
cs v[N];
cs Cuts(string str)
{
bool F=false;
cs ans;
int I;
for(I=0;;I++)
{
if(str[I]==’ ‘)break;
ans.zhu.push_back(str[I]);
}
if(ans.zhu!=“I” && ans.zhu!=“you”) ans.s=true;
if(ans.zhu==“everybody”)ans.j=true;
if(ans.zhu==“nobody”)ans.j=true,ans.f=true;
int J=I+1;I++;
string str1="";
for(;;I++)
{
if(str[I]==’ ‘)break;
if(str[I]==’.’){F=true;break;}
str1.push_back(str[I]);
}
if(str1==“don’t” || str1==“doesn’t”)
{
ans.f=!ans.f;
J=I+1,I++;str1="";
for(;;I++)
{
if(str[I]==’ ’ )break;
if(str[I]==’.’) {F=true;break;}
str1.push_back(str[I]);
}
}
if(ans.s==true)
{
if(str1[str1.length()-1]==‘s’)
str1.erase(str1.end()-1);
}
ans.wei=str1;
if(F) return ans;
J=I+1;I++;
for(;I<str.length()-1;I++)
{
ans.bin.push_back(str[I]);
}
return ans;
}
inline void judge(cs a,cs b)
{
if (a.wei!=b.wei || a.bin!=b.bin) return;
else
{
if(a.wei==b.wei&&a.bin==b.bin)
{
if(a.zhu==b.zhu)
{
if(a.f!=b.f)
E=1;
}
elif (a.j==1 || b.j==1)
{
if (a.f^b.f==1) E=1;
}
}
}
return;
}
int n;
string S;
inline string change(string s)
{
string a;
if(s==“I”) a=“you”;
elif(s==“you”) a=“I”;
else a=s;
return a;
}
deque Str;
deque Cs;
int main()
{
int m=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
m=0;
E=0;
if (i!=1)printf("\n");
printf(“Dialogue #%d:\n”,i);
while(1)
{
getline(cin,S);
int l=S.length();
switch(S[l-1])
{
case ‘!’:
{
cout<<S;
goto here;
}break;
case ‘.’:
{
m++;
v[m]=Cuts(S);
if(E==0)
for(int I=1;I<=m-1;I++)
judge(v[I],v[m]);
}break;
case ‘?’:
{
cout<<S<<endl;
if(E==true) printf(“I am abroad.\n”);
elif(S[0]==‘d’)//do/does
{
bool F=0;
int I;
for(I=0;;I++)
if(S[I]==’ ‘) break;
I++;
string str0="";string str1="",str2="";
for(;;I++)
{
if(S[I]==’ ‘) break;
str0.push_back(S[I]);
}
I++;
for(;;I++)
{
if(S[I]==’ ‘) break;
if(S[I]==’?’) {
F=1;break;
}
str1.push_back(S[I]);
}
if(!F){
I++;
for(;I<S.length()-1;I++)
{
if(S[I]==’\n’) break;
str2.push_back(S[I]);
}
}
if(m==0)printf(“maybe.\n”);
for(I=1;I<=m;I++)
{
if((v[I].zhu==str0||v[I].j==true) && v[I].wei==str1 && v[I].bin==str2)
if(str0!=“I” && str0!=“you”)
if (v[I].f)
{if(str2!="")cout<<“no, “<<str0<<” doesn’t “<<str1<<’ ‘<<str2<<’.’<<endl;
else cout<<“no, “<<str0<<” doesn’t “<<str1<<’.’<<endl;break;}
else
{if(str2!=””)cout<<“yes, “<<str0<<’ ‘<<str1<<"s "<<str2<<’.’<<endl;
else cout<<“yes, “<<str0<<’ '<<str1<<“s.”<<endl;break;}
else
{
if (v[I].f)
{if(str2!=””)cout<<“no, “<<change(str0)<<” don’t “<<str1<<’ ‘<<str2<<’.’<<endl;
else cout<<“no, “<<change(str0)<<” don’t “<<str1<<’.’<<endl;break;}
else
{if(str2!=””)cout<<“yes, “<<change(str0)<<’ ‘<<str1<<’ ‘<<str2<<’.’<<endl;
else cout<<“yes, “<<change(str0)<<’ ‘<<str1<<’.’<<endl;break;}
}
if(I==m)
printf(“maybe.\n”);
}
}
elif(S[2]==‘o’)//who
{
int I=0;
for(I=0;;I++)
if(S[I]==’ ') break;
I++;
bool F=0;
string str1=””,str2=””;
for(;;I++)
{
if(S[I]==’ ‘) break;
if(S[I]==’?’) {
F=1;break;
}
str1.push_back(S[I]);
}
str1.erase(str1.end()-1);
if(!F){
I++;
for(;I<S.length()-1;I++)
{
if(S[I]==’\n’) break;
str2.push_back(S[I]);
}
}
F=0;
if(m==0)
{
cout<<“I don’t know.\n”;
goto there;
}
for(I=1;I<=m;I++)
{
if(v[I].j==true && v[I].wei==str1 && v[I].bin==str2)
{
F=1;
if (v[I].f)
{
if(str2==””)
cout<<“nobody “<<str1<<“s”<<”.”<<endl;
else
cout<<“nobody “<<str1<<“s “<<str2<<”.”<<endl;
break;
}
else
{
if(str2==””)
cout<<“everybody “<<str1<<“s”<<”.”<<endl;
else
cout<<“everybody “<<str1<<“s “<<str2<<”.”<<endl;
break;
}
}
}
if (!F)
{
for(I=1;I<=m;I++)
{
if(v[I].wei==str1 && v[I].bin==str2 && v[I].f==0)
{
Str.push_back(v[I].zhu);
}
}
if(Str.empty()) printf(“I don’t know.\n”);
else
{
if(Str.size()==1)
{
if (Str.front()==“I” || Str.front()==“you”)
if(str2==””)
cout<<change(Str.front())<<’ '<<str1<<”.”<<endl;
else
cout<<change(Str.front())<<’ '<<str1<<” “<<str2<<”.”<<endl;
else
if(str2=="")
cout<<Str.front()<<’ ‘<<str1<<“s.”<<endl;
else
cout<<Str.front()<<’ ‘<<str1<<"s "<<str2<<’.’<<endl;
Str.pop_front();
}
else
{
F=0;
while(!Str.empty())
{
if(F==0)
{
cout<<change(Str.front());
F=1;
}
else
{
if(Str.size()==1)
{
cout<<" and “<<change(Str.front())<<’ '<<str1;
if(str2==”")
cout<<’.’<<endl;
else
cout<<’ ‘<<str2<<’.’<<endl;
}
else
{
cout<<", “<<change(Str.front());
}
}
Str.pop_front();
}
}
}
}
}
elif(S[2]==‘a’)//what
{
int I=0;
for(I=0;;I++)//what
if(S[I]==’ ‘) break;
I++;
for(;;I++)//do/does
if(S[I]==’ ') break;
I++;
string str0=”";
for(;;I++)//somebody
{
if(S[I]==’ ‘) break;
str0.push_back(S[I]);
}
if (m==0)printf(“I don’t know.\n”);
else
{
bool F=0;
for(I=1;I<=m;I++)
{
if(v[I].zhu==str0 || v[I].j)
Cs.push_back(v[I]);
}
if(Cs.empty()) printf(“I don’t know.\n”);
else
{
cout<<change(str0);
while(!Cs.empty())
{
if(Cs.size()==1 && F==0)
{
cout<<’ ‘;
if(Cs.front().f)
{if(str0!=“I”&&str0!=“you”)cout<<"doesn’t ";
else cout<<“don’t “;
cout<<Cs.front().wei;
if(Cs.front().bin!=””)cout<<’ ‘<<Cs.front().bin;}
else
{
cout<<Cs.front().wei;
if(str0!=“I”&&str0!=“you”)cout<<‘s’;
if(Cs.front().bin!="")cout<<’ ‘<<Cs.front().bin;
}
cout<<’.’<<endl;
}
elif(Cs.size()==1)
{
cout<<", and ";
if(Cs.front().f)
{
if(str0!=“I”&&str0!=“you”)cout<<“doesn’t “;
else cout<<“don’t “;
cout<<Cs.front().wei;
if(Cs.front().bin!=””)cout<<’ ‘<<Cs.front().bin;
}
else
{
cout<<Cs.front().wei;
if(str0!=“I”&&str0!=“you”)cout<<“s “;
if(Cs.front().bin!=””)cout<<Cs.front().bin;
}
cout<<’.’<<endl;
}
else
{
if(F)cout<<”, “;
else cout<<” “;
F=1;
if(Cs.front().f)
{
if(str0!=“I”&&str0!=“you”)cout<<“doesn’t “;
else cout<<“don’t “;
cout<<Cs.front().wei;
if(Cs.front().bin!=””)cout<<’ '<<Cs.front().bin;
}
else
{
cout<<Cs.front().wei;
if(str0!=“I”&&str0!=“you”)cout<<“s”;
if(Cs.front().bin!=””)cout<<’ '<<Cs.front().bin;
}
}
Cs.pop_front();
}
}
}
}
;
there:
;
printf(”\n”);
}break;
}
}
;
here:
;
}
return 0;
}