usaco 3.1 Contact


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <math.h>
using namespace std;
map<string,int>map1;
struct ttt{
int num;
string s;
};
ttt qq[305000];
string s1,s2,s3;
int cmp1(ttt x,ttt y){
    if(x.num!=y.num)
        return x.num>y.num;
    else if(x.s.size()!=y.s.size())
        return x.s.size()<y.s.size();
    else
        return x.s<y.s;
}
int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    freopen("contact.in","r",stdin);
    freopen("contact.out","w",stdout);
    int i,j,f1,f2,f3,l1,t1,t2,t3,t4,l2,l3;
    int n,m,len;
    int l,r;
    cin >> l >> r>> n;
    while(cin >> s2){
        s1=s1+s2;
    }
    int len1=s1.size();
    t1=0;
    for(i=0;i<len1;i++){
        string s4;s4.clear();
        for(j=0;j<r;j++){
                if(j+i>=len1)break;
            s4.push_back(s1[i+j]);
            if(j>=l-1&&map1[s4]==0){
               map1[s4]=++t1;
               qq[t1].num=1;
               qq[t1].s=s4;
      //         cout << s4<< endl;
            }else if(j>=l-1){
                qq[map1[s4]].num++;
            }
        }
    }
    sort(qq+1,qq+1+t1,cmp1);
    t3=qq[1].num;
    t2=0;
    cout << qq[1].num << endl;
    cout << qq[1].s << endl;
    t4=1;
    for(i=2;i<=t1;i++){
        if(qq[i].num==t3){
         if(t2==6){
            cout << endl;
            cout << qq[i].s;t2=1;continue;
         }
         t2++;
         cout <<" "<< qq[i].s;
        }else{
             if(t4==n){cout << endl;
        break;}
        if(i!=2)cout << endl;
        t4++;
        cout << qq[i].num<< endl;
        cout << qq[i].s;
        t2=1;
        t3=qq[i].num;
        }
        if(i==t1)cout << endl;
    }
    return 0;
}

就是用map对每个字符串的长度进行储存就好,然后排序的时候是根据出现次数,长度,大小分别为索引进行排序的。

注意输入的时候是分为多行输入即可

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值