Title Description
Obviously classmate recently fascinated by the detective Comics "Conan" and indulge in the reasoning game, so he called a group of students to play the reasoning game. The content of the game is like this, clearly the students first discussed by one of them to act as a criminal (in the case without knowing clearly), clearly the task is to find this criminal. Then, clearly asked each of the students, the respondents may say:
Other words appearing in the testimony are not included in the content of logical reasoning.
What plainly knows is that there are n people in his classmates who always say lies, the rest are always true.
Now, obviously need you to help him to infer from his classmate's words who is the real murderer, please remember that the murderer only one.
input
The input consists of several lines, the first line having two integers, M (1≤m≤20), N (1≤n≤m), and P (1≤p≤100);
M is the number of students who participate in the game, N is the number of people who always lie, p is the total number of testimonies. Next M line,
Each line is the name of a classmate (English alphabet, no main, all uppercase).
There are p lines, each line starts with a classmate's name, followed by a colon and a space, followed by a statement, in line with the format listed in the previous table. The testimony does not exceed 250 characters per line.
There are no contiguous two spaces in the input, and there are no spaces at the beginning and end of each line. Output
If your program can determine who is a criminal, output his name; If the program determines that more than one person may be
Criminals, the output cannot determine; If the program determines that no one can be a criminal, output impossible. Sample Input
2 2 4helloguiltyhello:what is your name? Guilty:i am guilty. Guilty:are you guilty? Hello:i am not guilty.
Sample Output
HELLO
The idea is to enumerate the days of the week then you can deduce it, the other ... See for yourself, last year wrote ...
#include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm
> Using namespace std;
map<string,int>map;
int num[105],f[21],m,n,i,j,k,p,flag,now,lie,len,cnt,today,t;
Char a[21][205],name[105][205],s[105][21][205],ans[101][205];
Char day[8][25]={"", "Monday.", "Tuesday.", "Wednesday.", "Thursday.", "Friday.", "Saturday.", "Sunday."};
BOOL CMP (char *a,char *b) {int L1=strlen (a), L2=strlen (b);
if (L1!=L2) return false;
for (int i=0;i<l1;i++) if (A[i]!=b[i]) return false;
return true; } int check1 (int k) {if (!cmp (S[k][num[k]], "guilty.") | | (num[k]!=3&&num[k]!=4))
return 2; if (s[k][1][0]!= ' I ' | | s[k][1][1]!= ' + ' | |!
CMP (s[k][2], "AM")) return 2;
if (num[k]==4&&!cmp (s[k][3], "not")) return 2;
if (Map[name[k]]==now) return num[k]!=3;
return num[k]==3; } int Check2 (int k) {if (!cmp (S[k][num[k]], "guilty.") | | (num[k]!=3&&num[k]!=4| |!
CMP (s[k][2], "is"))) return 2; if (num[k]==4&&!cmp (s[k)[3], "not")) return 2;
if (Map[s[k][1]]==now) return num[k]!=3;
return num[k]==3; } int check3 (int k) {if (num[k]!=3| |! CMP (S[k][1], "Today") | |!
CMP (s[k][2], "is")) return 2;
Return!cmp (day[today],s[k][3]);
} int work () {now=map[a[p]];
int r=0,another=0;
memset (F,0,sizeof (f));
for (int i=1;i<=m;i++) {int t1=check1 (i), T2=check2 (i), T3=check3 (i), pre=map[name[i]]; if (!t1| |! t2| |!
T3) {if (f[pre]==2) return 0;
F[pre]=1; } if (t1&1| | t2&1| |
t3&1) {if (f[pre]==1) return 0;
f[pre]=2;
}} for (int i=1;i<=n;i++) {if (f[i]==2) r++;
else if (!f[i]) another++;
} return (R<=lie&&r+another>=lie);
} int main () {cin>>n>>lie>>m;
for (i=1;i<=n;i++) {cin>>a[i];
Map[a[i]]=i;
} for (i=1;i<=m;i++) {cin>>name[i]; Name[i][strlen (NamE[i]) -1]= ' + ';
Num[i]=1;
cin>>s[i][num[i]];
while (Isalpha ((S[i][num[i]][strlen (S[i][num[i])-1])) cin>>s[i][++num[i]];
} for (p=1;p<=n;p++) {flag=0;
for (today=1;today<=7&&!flag;today++) flag=work ();
if (flag) memcpy (ans[++cnt],a[p],sizeof (a[p]));
} if (!cnt) cout<< "impossible";
else if (cnt==1) cout<<ans[cnt];
Else cout<< "cannot determine";
return 0; }