1018

作者: 峡迩 | 来源:发表于2017-07-22 22:29 被阅读0次
    #include<iostream>
    #include<array>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    
    class games
    {
    public:
        games() = default;
        games(istream &in) { in >> a >> b; }
        int get_result_a();
        string get_a()const { return a; }
        string get_b()const { return b; }
    
    private:
        string a;
        string b;
    };
    
    int games::get_result_a()   //返回值0代表平局,1代表胜利,-1代表失败
    {
        if (a == "C")
        {
            if (b == "C")
                return 0;
            if (b == "J")
                return 1;
            if (b == "B")
                return -1;
        }
        if (a == "J")
        {
            if (b == "J")
                return 0;
            if (b == "B")
                return 1;
            if (b == "C")
                return -1;
        }
        if (a == "B")
        {
            if (b == "B")
                return 0;
            if (b == "C")
                return 1;
            if (b == "J")
                return -1;
        }
    }
    
    const string max_vin(vector<string> &a)
    {
        unsigned v_c = count(a.cbegin(), a.cend(), "C");
        unsigned v_j = count(a.cbegin(), a.cend(), "J");
        unsigned v_b = count(a.cbegin(), a.cend(), "B");
    
        if (v_b >= v_c && v_b >= v_j)
            return "B";
        if (v_j > v_b && v_j > v_c)
            return "J";
        if (v_c >= v_j && v_c > v_b)
            return "C";
    }
    
    
    int main()
    {
        unsigned n;
        cin >> n;
    
        vector<games> play_game;
        while (n>0)
        {
            games tmp(cin);
            play_game.push_back(tmp);
            --n;
        }
    
        vector<string> a_result, b_result;
        unsigned pj = 0;
        for (auto &r : play_game)
        {
            if (1 == r.get_result_a())
                a_result.push_back(r.get_a());
            if (-1 == r.get_result_a())
                b_result.push_back(r.get_b());
            if (0 == r.get_result_a())
    
                ++pj;
        }
    
        cout << a_result.size() << " " << pj << " " << b_result.size() << endl;
        cout << b_result.size() << " " << pj << " " << a_result.size() << endl;
    
        cout << max_vin(a_result) << " " << max_vin(b_result);
    
        cout << endl;
        system("pause");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:1018

          本文链接:https://www.haomeiwen.com/subject/avcpkxtx.html