7-16 新浪微博热门话题 (30分)

#include<bits/stdc++.h>
using namespace std;
map<string, int> topics;
int Max = 0;
string  Insert_map(string str)
{
    for(int i = 0; i < str.size(); i++)
    {
        if(str[i] >= 'A' && str[i] <= 'Z')
        {
            str[i] += 32;
            continue;
        }
        else if((str[i] >= '0' && str[i] <= '9') || str[i] >= 'a' && str[i] <= 'z')
            continue;
        else
            str[i] = ' ';
    }
    for(int i = 0; i < str.size(); i++)
    {
        if(str[i] == ' ')
        {
            if(i == 0 || i == str.size() - 1)
            {
                str.erase(i, 1);
                i--;
            }
            else if(i != str.size() - 1)
                if(str[i + 1] == ' ')
                {
                    str.erase(i, 1);
                    i--;
                }
        }
    }
    return str;
}
void process_str(string In_str)
{
    string str;
    map<string, int> map1;
    int flag = 0, pos_s = 0, pos_e = 0;
    int N = In_str.length();
    for(int i = 0; i < N ; i++)
    {
        if(In_str[i] == '#' && flag == 0)
        {
            pos_s = i;
            flag = 1;
            continue;
        }
        if(In_str[i] == '#' && flag == 1)
        {
            flag = 0;
            if (pos_e == pos_s + 1)
                continue;
            pos_e = i;
            str.assign(In_str.begin() + pos_s + 1, In_str.begin() + pos_e);
            string str2;
            str2 = Insert_map(str);
            if(str2 == " " || str2 == "")
                continue;
            if(map1.count(str2) == 0)
                map1.insert(make_pair(str2, 1));
        }
    }
    map<string, int>::iterator iter;
    for(iter = map1.begin(); iter != map1.end(); iter++)
    {
        if(iter->first == " ")
            continue;
        if(topics.count(iter->first) != 0)
            topics[iter->first] += 1;
        else
            topics.insert(make_pair(iter->first, 1));
        if(topics[iter->first] > Max)
            Max = topics[iter->first];
    }

}
int main()
{
    string In_str, str;
    int N;
    scanf("%d", &N);
    getchar();
    for(int i =0; i < N; i++)
    {
        getline(cin, In_str);
        process_str(In_str);
    }
    map<string, int>::iterator iter;
    int flag = 0;
    int n = 0;
    for(iter = topics.begin(); iter != topics.end(); iter++)
    {
        if(iter->second == Max)
        {
            if(flag != 0)
            {
                if(In_str > iter->first)
                    In_str = iter->first;
            }
            else
                In_str = iter->first;
            flag++;
            n++;
        }
    }
    if(In_str[0] >= 'a' && In_str[0] <= 'z')
        In_str[0] = In_str[0] - 32;
    cout << In_str << endl;
    cout << Max << endl;
    if(n != 1)
        cout << "And " << n - 1 << " more ...";

}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值