• ZOJ 3700 Ever Dream(Vector)


    做了这道题,算是会vector了。

    /*
    Problem :
    Status  :
    By wf,
    */
    
    #include "algorithm"
    #include "iostream"
    #include "cstring"
    #include "cstdio"
    #include "string"
    #include "stack"
    #include "cmath"
    #include "queue"
    #include "set"
    #include "map"
    
    #define lson l , m , rt << 1
    #define rson m + 1 , r , rt << 1 | 1
    
    typedef long long ll;
    using namespace std;
    
    const int inf=0x3f3f3f3f;
    const int maxn=1e5+5;
    
    int t;
    int n;
    
    map<string,int>mp;
    vector<string>v[maxn];
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        cin>>t;
        while(t--)
        {
            mp.clear();
    
    
            for(int i=0;i<maxn;++i)v[i].clear();
    
            cin>>n;
            getchar();
            string str;
            for(int i=0; i<n; ++i)
            {
                getline(cin,str);
                //cout<<str<<endl;
    
                int len = str.length();
                for(int i=0; i<len;)
                {
                    if( isalpha(str[i]) )
                    {
                        str[i]=tolower(str[i]);
                        int j = i + 1;
                        while(j<len && isalpha(str[j]))
                        {
                            str[j]=tolower(str[j]);
                            j++;
                        }
                        string word = str.substr(i,j-i);
                        mp[word]++;
                        //cout<<word<<" "<<endl;
                        i=j;
                    }
                    else i++;
                }
            }
            map<string,int>::iterator it;
            for(it=mp.begin(); it!=mp.end(); ++it)
            {
                //cout<< it->first <<endl;
    
                if(it->second==1)continue;
    
                if( v[ it->second ].empty() )
                {
                     v[ it->second ].push_back( it->first );
                }
                else
                {
                    int len1 = it->first.length();
                    int len2 = v[ it->second ].front().length();
                    if( len1 > len2 )
                    {
                        v[ it->second ].clear();
                        v[ it->second ].push_back( it->first );
                    }
                    else if( len1==len2 )
                    {
                        v[ it->second ].push_back( it->first );
                    }
                }
    
            }
            bool first=1;
            for(int i=maxn-1;i>=2;--i)
            {
                if( v[i].empty() )continue;
                int num = v[i].size();
                if( num==1 )
                {
                    if(first)first=0;
                    else cout<<" ";
    
                    cout<<v[i].front();
                    //cout<<" "<<mp[  v[i].front()   ]<<endl;
                }
                else
                {
                    sort(v[i].begin(),v[i].end());
    
                    if(first)first=0;
                    else cout<<" ";
    
                    v[i].pop_back();
                    cout<<v[i].back();
    
                    //cout<<" "<<mp[ v[i].back()  ]<<endl;
                }
    
                //debug
                /*
                if( i==2 )
                {
                    vector<string>::iterator it2;
                    it2 = v[i].begin();
                    while( it2!=v[i].end() )
                    {
                        cout<<"2:"<< *it2 <<endl;
                        ++it2;
                    }
                }
                */
            }
            cout<<endl;
    
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    原生js片段
    IE 怪异模式(Quirks Mode)对 HTML 页面的影响
    CSS3 @font-face 的使用
    css面试题——九宫格
    一些前端冷知识
    利用 document.domain 在当前的域名或者基础域名 实现跨域
    JS 判断浏览器客户端类型(ipad,iphone,android)
    防止网站被iframe调用
    doctype 的各种声明
    JQUERY中的事件处理:RETURN FALSE、阻止默认行为、阻止冒泡以及兼容性问题
  • 原文地址:https://www.cnblogs.com/bruce27/p/5487206.html
Copyright © 2020-2023  润新知