奮戰杭電ACM(DAY3)1004

這道題好簡單,沒用任何算法直接做了……方法很笨,不過穩紮穩打一次AC!再搜一搜有沒有很巧妙的解法!

Let the Balloon Rise

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

int main()
{
    int nmax,N,j,i;
    string max;
    nmax=0;
    while(cin >> N)
    {    if(N==0)
            break;
    else
        {string *p = new string[N+1];
    for(i=1; i<=N; i++)
        cin >> p[i];
    max=p[1];
    for(i=1; i<=N; i++)
    {
        string temp;
        int ntemp;
        temp=p[i];
        ntemp=0;
        for(j=1; j<=N; j++)
        {
            if(p[j]==p[i])
                ntemp +=1;
        }
        if(ntemp >= nmax)
            nmax = ntemp,max=p[i];
    }
    cout << max << endl; 
    }
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章