杭电1004

输入字符串,并比较输入频率最大的那个字符串

难点:1.字符串的比较 可以用strcmp(a,b),若相等,则返回的是0,若不等,返回1!别弄错咯

#include<iostream>
using namespace std;
int  main( )
{
    int round;
    cin >> round;
    while (round)
    {
        char ballo[1001][16];
        int fre[1001] = { 0};
        char tem[15];
        int m = 0, n = 0;
        int count = 0;
        for (int i = 0; i < round; i++)
        {
            cin >> tem;
            int j = 0;
            while (j != i && strcmp(tem,ballo[j]))
            {
                j++;
            }
            if (!strcmp(tem,ballo[j]))
                fre[j]++;
            else
            {
                strcpy_s(ballo[j], tem);
                fre[j]++;
                count++;
            }
        }
        int max = fre[0];
        int pos = 0;
        for (int u = 0; u < count; u++)
        {
            if (fre[u]>max)
            {
                max = fre[u];
                pos = u;
            }
        }
        cout << ballo[pos]<<endl;
        cin >> round;
    }
    return 0;
}


Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2016 HDU ACM Team. All Rights Reserved.
Designer & Developer Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2016-04-06 21:16:47, Gzip enabled
 
 
posted @ 2016-04-06 21:18  陈xx有在努力变大神  阅读(205)  评论(1)    收藏  举报