ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 C (map模拟)

一开始想多了以为是AC自动机或者Tire之类的,后来发现直接用map<pair<string,string>,int>模拟即可。

就是想办法处理掉那些多余的空格和逗号句号,其实还是比较啰嗦,慢慢写就好


【代码】

/* ***********************************************
Author        :angon

************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define showtime fprintf(stderr,"time = %.15f\n",clock() / (double)CLOCKS_PER_SEC)
#define lld %I64d
#define REP(i,k,n) for(int i=k;i<n;i++)
#define REPP(i,k,n) for(int i=k;i<=n;i++)
#define scan(d) scanf("%d",&d)
#define scanl(d) scanf("%I64d",&d)
#define scann(n,m) scanf("%d%d",&n,&m)
#define scannl(n,m) scanf("%I64d%I64d",&n,&m)
#define mst(a,k)  memset(a,k,sizeof(a))
#define LL long long
#define N 1005
#define mod 1000000007
inline int read(){int s=0;char ch=getchar();for(; ch<'0'||ch>'9'; ch=getchar());for(; ch>='0'&&ch<='9'; ch=getchar())s=s*10+ch-'0';return s;}

map<pair<string,string>,int>mp;

char str[1000];
char first[500],second[500];
string ans1,ans2;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int j=0,ans=0,flag1=0,flag2=0;
    while(gets(str))
    {
        if(str[0] == '#')
        {
            map<pair<string,string>,int>::iterator it;
            ans = 0;
            for(it = mp.begin();it!=mp.end();it++)
            {
                if(ans < it->second)
                {
                    ans = it->second;
                    ans1 = (it->first).first ;
                    ans2 = (it->first).second;
                }
            }
            cout<<ans1<<' '<<ans2<<':';
            cout<<ans<<endl;

            mp.clear(); 
            j=0;flag1=flag2=0;
            continue;
        }
        int len = strlen(str);
        flag1 = 0; flag2 = 0;
        for(int i = 0;i<len;i++)
        {
            while(str[i]==' ' && i<len)
            {
                i++;
            }
            if(str[i]==',' || str[i]=='.')
            {
                flag1 = 0;
                mst(second,0);
                continue;
            }
            j=0;
            int f=0;
            flag2 = 0;
            while(str[i]>='a' && str[i]<='z' && i<len)
            {
                second[j++] = str[i];
                i++;
                f=1;
                flag2=1;
            }
            if(f) i--;
            if(flag1 && flag2)
                mp[make_pair(first,second)] ++;
            strcpy(first,second);
            mst(second,0);
            flag1 = flag2;
        }

    }


    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值