zoj2104

来源:互联网 发布:js new一个对象 编辑:程序博客网 时间:2024/06/10 08:17

容器用起来还是很方便的。


#include <iostream>#include <string>#include <vector>using namespace std;int main(){    int num;    while(cin >> num && num)    {        vector<string> popular;        while(num--)        {            string color;            cin >> color;            popular.push_back(color);        }        int maxnum = 0,num = 0;        string popu;        for(vector<string>::iterator itbegin = popular.begin();itbegin != popular.end();itbegin++)        {            num = 0;            for(vector<string>::iterator it = itbegin;it != popular.end();it++)            {                if(*it == *itbegin)                    num ++;            }            if(num > maxnum)            {                maxnum = num;                popu = *itbegin;            }        }        cout << popu << endl;    }    return 0;}


0 0
原创粉丝点击