文章
84
粉丝
408
获赞
33
访问
867.6k
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef map<string, int> msi;
int main()
{
char line[1024], str[20];
cin.getline(line, 1024);
msi words;
int i = 0, head = 0, len = 0;
while (line[i]) {
if (line[i] == ' ' || line[i] == ',' || line[i] == '.') {
if (len > 0) {
memset(str, 0, sizeof(str));
strncpy(str, line+head, len);
words[str]++;
len = 0;
}
i++;
head = i;
}
else if (line[i] >= 'A' && line[i] <= 'Z') {
line[i] += ('a'-'A');
len++;
i++;
}
else if (line[i] >= 'a' && line[i] <= 'z') {
len++;
i++;
}
}
msi::iterator itr;
msi::iterator maxn;
while (!words.empty()) {
maxn = words.begin();
for (itr = words.begin(); itr != words.end(); itr++) {
if (itr->second > maxn->second)
maxn = itr;
else if (itr->second == maxn->s...
登录后发布评论
暂无评论,来抢沙发