UVa 1186 - Chat Rooms

contents

  1. 1. Problem
  2. 2. Sample Input
  3. 3. Sample Output
  4. 4. Solution

Problem

聊天室會過濾過機器人般的垃圾留言,規則如下

  • 使用的單詞,出現連續子音的個數大於 5 個
  • 使用者最後送出的 10 個訊息中,有 2 行連續子音的個數大於 4 個,並且當前行也存在連續子音的個數大於 4 個。
  • 使用者最後送出的 10 個訊息中,與當前訊息相同的行數大於 1 個。

只要符合其中一條,訊息將無法發送,但是系統仍然會記錄下你曾經發送過的訊息,其他使用者無法看到被過濾的訊息。

Sample Input

1
2
3
4
5
6
7
8
9
10
11
12
13
12
hello
how r u?
where r u from?
kjhh kh kgkjhg jhg
where r u from?
i am from London, Ontario, Canada
how r you nxw?
now
where r u from?
kjhh kh kgkjhg jhg
very good
it is very cold here.

Sample Output

1
2
3
4
5
6
7
8
9
10
11
12
y
y
y
n
y
y
y
y
n
n
y
y

Solution

這題算簡單,但是題目描述過於鬼畜。

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
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <ctype.h>
using namespace std;
vector<string> toToken(string s) {
stringstream sin(s);
string token;
vector<string> r;
while (sin >> token)
r.push_back(token);
return r;
}
int isConsonant(char c) {
c = tolower(c);
if (c == 'a') return 0;
if (c == 'e') return 0;
if (c == 'i') return 0;
if (c == 'o') return 0;
if (c == 'u') return 0;
if (c == 'y') return 0;
return 1;
}
int checkCond1(vector<string> &t) {
for (int i = 0; i < t.size(); i++) {
int c = 0;
for (int j = 0; j < t[i].length(); j++) {
if (isConsonant(t[i][j]))
c++;
else
c = 0;
if (c > 5) return 0;
}
}
return 1;
}
int checkCond2(vector<string> &t, vector<int> &D2) {
int A = 0, B = 0;
for (int i = 0; i < t.size(); i++) {
int c = 0;
for (int j = 0; j < t[i].length(); j++) {
if (isConsonant(t[i][j]))
c++;
else
c = 0;
if (c > 4) A = 1;
}
}
for (int i = D2.size() - 1; i >= max(0, (int) D2.size() - 10); i--) {
if (D2[i] > 0)
B++;
}
return !(A && B > 2);
}
int checkCond3(string s, vector<string> &D3) {
int A = 0;
for (int i = D3.size() - 1; i >= max(0, (int) D3.size() - 10); i--) {
if (D3[i] == s)
A++;
if (A > 1)
return 0;
}
return 1;
}
int count4(vector<string> &t) {
int A = 0;
for (int i = 0; i < t.size(); i++) {
int c = 0;
for (int j = 0; j < t[i].length(); j++) {
if (isConsonant(t[i][j]))
c++;
else
c = 0;
if (c > 4) A = 1;
}
}
return A;
}
int main() {
int n;
char s[256];
while (scanf("%d", &n) == 1) {
while (getchar() != '\n');
vector< vector<string> > D;
vector<int> D2;
vector<string> D3;
for (int i = 0; i < n; i++) {
gets(s);
vector<string> t = toToken(s);
int ok = 1;
if (!checkCond1(t))
ok = 0;
else if (!checkCond2(t, D2))
ok = 0;
else if (!checkCond3(s, D3))
ok = 0;
D.push_back(t), D2.push_back(count4(t)), D3.push_back(s);
puts(ok ? "y" : "n");
}
}
return 0;
}