zoukankan      html  css  js  c++  java
  • uva 11572

    本书是关于使用刘汝佳set,

    通过收集找到.count()和删除.erase().这种方法比我好。用较短的时间。

    我想map这个任务可以完成。但是,这是不容易删除,必须先找到find()标。然后删除索引对应的元素

    但map有map的使用方法。以下的方法就是比較easy实现的一种方法。

    我本想着这个一边读完就计算出了ans,应该更快一点的。可是其实还不如先读再用set处理来得快。

    #include<cstdio>
    #include<iostream>
    #include<map>
    #include<string>
    #include<algorithm>
    using namespace std;
    
    map<string,int> ma;
    
    int main()
    {
        int t,n;
        int ans=0;
        scanf("%d",&t);
        while(t--)
        {
            ans=0;
            scanf("%d",&n);
            ma.clear();
            string s1;
            int L=0,R=0;
            for(int i=0;i<n;i++)
            {
                cin>>s1;
                if(ma.count(s1)&&ma[s1]>=L)
                {
                    L=ma[s1]+1;
                }
                R++;
                ans=max(ans,R-L);
                ma[s1]=i;
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    


    版权声明:转载请注明出处凯撒...http://blog.csdn.net/u013382399

  • 相关阅读:
    netty ByteToMessageDecoder 分析
    netty 编/解码处理
    MAC 入门
    netty 学习
    php ioc and web rest design
    spring 启动流程
    淘宝美衣人
    ecslipe cdt lib link
    阿里巴巴中间件团队招人了!
    架构师速成-架构目标之伸缩性安全性
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4732676.html
Copyright © 2011-2022 走看看