zoukankan      html  css  js  c++  java
  • 杭电OJ 1004

    #include <iostream>
    #include <string>
    using namespace std;
    #define FOR(i,a,b) for(int i=(a);i<(b);++i)
    #define RANGE(i,a) for(int i=0;i<(a);++i)
    #define SWAP(a,b) auto c=a;a=b;b=c;
    
    
    int main()
    {
        int n;
        string colors[1001], color;
        int amount[1001], color_amount;
    
        cin >> n;
        while (n != 0){
            color_amount = 0;
            FOR(i,0,n){
                cin >> color;
                bool found = false;
                RANGE(j, color_amount){
                    if (colors[j] == color){
                        amount[j] += 1;
                        found = true;
                    }
                }
                if(!found){
                    colors[color_amount] = color;
                    amount[color_amount] = 1;
                    color_amount ++;
                }
            }
            int max = 0, max_index = 0;
            RANGE(i, color_amount){
                if(amount[i] > max){
                    max_index = i;
                    max = amount[i];
                }
            }
            cout << colors[max_index] << endl;
            cin >> n;
        }
        return 0;
    }

    很简单的题目,用 string 可以避免使用 strcmp 时的麻烦。

  • 相关阅读:
    K
    A
    C
    E
    2020/9/14
    hdu5306 hdu3954 cf438D
    2020/9/10-9/11
    题解
    2020/8/31
    2020/8/30
  • 原文地址:https://www.cnblogs.com/KakagouLT/p/13049111.html
Copyright © 2011-2022 走看看