zoukankan      html  css  js  c++  java
  • HDOJ 1004--Let the Balloon Rise

    题目的意思就是要统计一系列字符串中某一个字符串出现的最多次数。

    刚开始的时候,想到使用map来处理map<string,int> 字符串,出现的次数,读入一个就在其中查找如果存在 int  +1;

    最后找到最大的int对应的string 就ok了……

    本人技拙,不知道怎么处理,望大神们赐教……

    还是说说,AC的做法:

    使用vector<string>来处理

    读入全部的元素之后,对所有的元素排序(方便查找相同的元素),然后在判断每个元素的次数,找出次数最大的对应的string,OK!

    #include<iostream>
    #include<string>
    #include<vector>
    #include<algorithm>
    using namespace std;
    int main()
    {
        string str;
        int n;
        vector<string> svec;
        while(cin>>n && n != 0)
        {
            int maxn = 1;
    		string maxstr;
            vector<string>::size_type index = 0;
            while(n--)
            {
                cin>>str;
                svec.push_back(str);
            }
            sort(svec.begin(),svec.end());
    
            maxstr = svec[index];
            str = svec[index];
    
            int c = 0;
            while(index < svec.size())
            {
                while( index < svec.size() && str == svec[index])
                {
                    c++;
                    index++;
                }
                if(c>maxn)
                {
                    maxn = c;
                    c =0;
                    maxstr = svec[index-1];
                }
                if(index == svec.size())
                    break;
                else
                    str = svec[index];
    			c=0;
            }
            cout<<maxstr<<endl;
            svec.clear();
    
        }
    
        return 0;
    }
    
  • 相关阅读:
    Bit Calculation
    Create ArcGIS maps in Power BI Desktop
    Power Apps visual for Power BI
    Create Power BI visuals by using Python
    运行 R 脚本
    Introduction to ASP.NET Core Blazor
    Tips and tricks for color formatting in Power BI
    Sharepoint Create, Update, and Delete List Items
    Power BI Office Online Server
    jQuery Organization Chart
  • 原文地址:https://www.cnblogs.com/plxx/p/3236489.html
Copyright © 2011-2022 走看看