2016北京网络赛C hihocoder

个人觉得就是考察STL
#include <bits/stdc++.h>

using namespace std;

const int maxn = 550;
char save[maxn];
string S[maxn];
int Scount=0;
char Str[maxn];
map<string,int>Map;
stringstream stream;

int cmp(const string &str1,const string &str2)
{
    return str1 > str2;
}

bool isword(int i){
    if(Str[i] != ' ' && Str[i] != '.' && Str[i] != ',') return true;
    return false;
}

int getMap(){
    string a,b;
    stream.clear();
    stream << save;
    stream >> a >> b;
    string in = a + " " + b;
    S[Scount++] = in;
    ++Map[in];
    stream.clear();
    memset(save,0,sizeof(save));
    stream << b;
    stream >> save;
    return b.length();
}

void slove(){
    sort(S,S+Scount,cmp);
    int ans = 0;
    int index = -1;
    //for(int i = 0;i < Scount; i++) cout<<S[i]<<endl;
    for(int i = 0;i < Scount; i++){
        if(ans <= Map[ S[i] ]){
            ans = Map[ S[i] ];
            index = i;
        }
    }
    cout<<S[index]<<":"<<ans<<endl;
}

int main()
{
    while(gets(Str)){
        int len = strlen(Str);
        if(Str[0] == '#'){
            slove();
            Scount=0;
            for(int i=0;i<maxn;i++) S[i].clear();
            Map.clear();
            continue;
        }
        int words=0,space=0;
        int Count=0;
        memset(save,0,sizeof(save));
        for(int i = 0; i < len; i++){
            if(isword(i)) {
                if(words == 1) save[Count++] = ' ';
                ++words;
                for(int j = i;isword(j) && j<len;j++){
                    save[Count++] = Str[j];
                    i = j;
                }
                //cout<<save<<"***"<<i<<endl;
                //cout<<words<<"****"<<space<<endl;
                //system("pause");
            }
            else{
                if(Str[i] == '.' || Str[i] == ',') {
                    Count = 0;
                    words = 0;
                    space = 0;
                    memset(save,0,sizeof(save));
                }
                else{
                    for(int j = i;Str[j]==' ' && j<len;j++){
                        i = j;
                    }
                    ++space;
                }
            }
            if(space == 1 && words == 2){
                words = 1;
                space = 0;
                //cout<<save<<endl;
                Count = getMap();
                //cout<<save<<endl;
                //system("pause");
            }
        }
        memset(Str,0,sizeof(Str));
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值