• zoj 2104


    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <map>
    using namespace std;

    int main()
    {

    int n,i,j;
    string s;
    map<string,int>m;
    map<string,int> :: iterator it,it2;
    while(cin>>n && n)
    {
    m.clear();
    for(i=0;i<n;i++)
    {
    cin>>s;
    if(m.find(s)!=m.end())//找到了就 加1
    m[s]+=1;
    else m[s]=1; //没找到就 =1,还可以再用,技巧,可省去vector的使用,边输入,边统计,迭代,高效。
    }
    it2=m.begin();
    for(it=m.begin();it!=m.end();it++)
    {
    if(it2->second<it->second)
    it2=it;//it2->second=it->second;
    } //note that the exchanged thing is the whole not only parts of it
    //in the iterator of it2 which is just a cup!
    cout<<it2->first<<endl;
    }
    // system("pause");
    return 0;
    }

    //新波动(754369601) 11:11:25


    zoj 2104:


    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    map <string,int>my;
    map <string,int>::iterator it;
    int main(int argc, char *argv[])
    {
    int n;string s,s1;int Max;
    while(cin>>n,n)
    {
    Max=0;
    while(n--)
    {cin>>s;my[s]++;}
    for(it=my.begin();it!=my.end();it++)
    {
    if(Max<(*it).second)
    {
    Max=(*it).second;
    s1=(*it).first;
    }
    }cout<<s1<<endl;
    my.clear();
    }
    return 0;
    }


    ********************************************************************************************************************8


    //[--李吉环--]<lijihuan0@qq.com> 11:12:44


    zoj 2104


    #include<algorithm>
    #include<cstdio>
    #include<iostream>
    #include<map>
    using namespace std;
    map<string,int> m;
    map<string,int>::iterator it;
    int main()
    {
    int n;
    char x[100];
    while(scanf("%d",&n),n!=0)
    {
    m.clear();
    while(n--)
    {
    scanf("%s",x);
    m[x]++;
    }
    int max=0;
    string color;
    for(it=m.begin();it!=m.end();it++)
    {
    if(max<it->second)
    {
    color=it->first;
    max=it->second;
    }
    }
    printf("%s ",color.c_str());
    }
    }

  • 相关阅读:
    第2课 有符号与无符号
    第1课 基本数据类型
    HDU 5821 Ball
    Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
    HDU 5810 Balls and Boxes
    HDU 5818 Joint Stacks
    HDU 5813 Elegant Construction
    Codeforces Round #357 (Div. 2)C. Heap Operations
    Codeforces Round #364 (Div. 2) C. They Are Everywhere
    HDU5806 NanoApe Loves Sequence Ⅱ
  • 原文地址:https://www.cnblogs.com/2014acm/p/3903236.html
Copyright © 2020-2023  润新知