题面
首先读入,我用了正则表达式判合法性
然后枚举凶手和日期
判断合法
注意只说闲话的人可能说真,可能说假1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94const readline = require("readline")
const IO = readline.createInterface(process.stdin, process.stdout);
const day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
var n, m, p, ok = 0;
var nowline = 0, nameline;
var words = [], name = [];
IO.on("line", function(line) {
if(nameline) {
nameline -= 1;
name.push(line);
return;
}
nowline += 1;
if(nowline == 1) {
let list = line.split(" ");
n = Number(list[0]);
m = Number(list[1]);
p = Number(list[2]);
// console.log(n, m, p);
nameline = n;
return;
}
list = line.split(":");
list[0] = list[0].trim();
list[1] = list[1].trim().replace(".", "");
if(words[list[0]] == undefined) words[list[0]] = [];
if(list[1].match(/(Today is [A-Z]*)|([A-Z]* is (not )?guilty)|(I am (not )?guilty)/gi) != null) words[list[0]].push(list[1]);
if(nowline == p + 1) main();
});
IO.on("close", function() {
process.exit();
})
var d, gu, err;
function check(name) {
if(words[name] == undefined) return -1;
let now = -1;
for(sen of words[name]) {
let nowp;
let list = sen.split(' ');
// console.log(sen);
// console.log(list);
if(list[1] == "am") {
nowp = (name == gu);
if(list[2] == "not") nowp = !nowp;
}
else if(list[0] == "Today") {
nowp = (d == list[2]);
}
else if(list[1] == "is") {
nowp = (list[0] == gu);
if(list[2] == "not") nowp = !nowp;
}
// console.log(nowp);
if(now == -1) now = nowp;
else if(now != nowp) {
err = 1;
return;
}
}
return now;
}
function main() {
// console.log(words);
let ans = "", _min, _max;
for(gu of name) {
for(d of day) {
// console.log(gu, d);
err = 0;
_min = _max = 0;
for(peo of name) {
var lala = check(peo);
if(err == 1) break;
if(lala == -1) _max ++;
else if(lala == 0) _min++, _max++;
}
// console.log(err, _min, _max);
if((err == 0) && (m <= _max) && (m >= _min)) {
if(ans == "") {
ans = gu;
break;
}
else {
console.log("Cannot Determine");
IO.close();
return;
}
}
}
}
if(ans == "") console.log("Impossible");
else console.log(ans);
IO.close();
}