-
Notifications
You must be signed in to change notification settings - Fork 0
/
1071.cpp
97 lines (89 loc) · 1.75 KB
/
1071.cpp
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
#include <iostream>
#include <string>
#include <map>
using namespace std;
#define MAX_LENGTH 1048576+100
char buffer[MAX_LENGTH];
char input[MAX_LENGTH];
map<string, int> records;
int length = 0;
inline bool is_small_alpha(char target)
{
return ('a' <= target && 'z' >= target);
}
inline bool is_big_alpha(char target)
{
return ('A' <= target && 'Z' >= target);
}
inline bool is_number(char target)
{
return ('0' <= target && '9' >= target);
}
inline bool is_alphanum(char target)
{
return (('a'<=target && 'z'>=target) || ('A'<=target && 'Z'>=target) || ('0'<=target && '9'>=target));
}
void preocess_input()
{
int index = 0;
int startpos = 0;
int endpos = 0;
string str;
while (input[endpos] != '\0')
{
while (input[startpos] == ' ')
{
++startpos;
}
endpos = startpos+1;
while (input[endpos] != '\0' && input[endpos] != ' ')
{
++endpos;
}
for (index = 0; index != endpos - startpos; ++index)
{
buffer[index] = input[index+startpos];
}
buffer[index] = '\0';
str = buffer;
++records[str];
startpos = endpos;
}
}
int main()
{
int maxnum = 0;
map<string, int>::iterator result;
cin.getline(input, MAX_LENGTH);
while (input[length] != '\0')
{
if ('A' <= input[length] && 'Z' >= input[length])
{
input[length] += 'a' - 'A';
}
else
{
if (('a'<=input[length] && 'z'>=input[length]) || ('0'<=input[length] && '9'>=input[length]))
{
// 条件判断太不好写,故意留空
}
else
{
input[length] = ' ';
}
}
++length;
}
preocess_input();
for (map<string, int>::iterator iter = records.begin(); iter != records.end(); ++iter)
{
if (maxnum < iter->second)
{
result = iter;
maxnum = iter->second;
}
}
cout << result->first << ' ' << result->second << endl;
system("pause");
return 0;
}