第一次玩ACM。。。有点小紧张小兴奋。这题目好难啊,只是网赛就这么难。。。只把最简单的两题做出来了。
题目1:
代码:
1 | //#define _ACM_ |
题目3:
代码: 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//#define _ACM_
using namespace std;
inline bool isch(char c) { return c >= 'a' && c <= 'z'; }
char ch, line[555], word[555];
string pr;
map<string, unsigned> phs;
int main()
{
freopen("in.txt", "r", stdin);
ch = getchar();
while (true) {
char *p(word);
while (isch(ch)) {
*p++ = ch;
ch = getchar();
}
*p = '\0';
bool ispunc(false);
while (ch != EOF && !isch(ch) && ch != '#') {
if (ch == ',' || ch == '.' || ch == '\n') ispunc = true;
ch = getchar();
}
if (ch == EOF) break;//the end of test file
else if (ch == '#') {//the end of current text
if (!pr.empty()) ++phs[pr + ' ' + word];
if (ispunc) pr.clear();
else pr = word;
unsigned maxu = 0;
string maxs;
for (const auto& r : phs)
if (r.second > maxu) maxu = r.second, maxs = r.first;
printf("%s:%u\n", maxs.c_str(), maxu);
phs.clear(), pr.clear();
getchar(), getchar(), getchar(), getchar();
ch = getchar();
}
else {//find a word/phrase
if (!pr.empty()) ++phs[pr + ' ' + word];
if (ispunc) pr.clear();
else pr = word;
}
}
return 0;
}