ITSA [C_SO41-中] 撲克牌排序

Problem

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=20772

Thinking

TODO

Solution

#include
#include
#include
using namespace std;

int POKER_PRIORITY[14] = {-1,12,13,1,2,3,4,5,6,7,8,9,10,11};

bool comp(int a,int b)
{
    return POKER_PRIORITY[a] > POKER_PRIORITY[b];
}
int main()
{
    int face;
    vector cards;
    while(cin >> face)
    {
        if(face == 0)
            break;
        
        cards.push_back(face);
    }
    
    sort(cards.begin(),cards.end(),comp);
    
    for(vector::iterator it = cards.begin() ; it != cards.end() ; ++it)
    {
        if(*it == 13)
            cout << "K" << endl;
        else if(*it == 12)
            cout << "Q" << endl;
        else if(*it == 11)
            cout << "J" << endl;
        else
            cout << *it << endl;
    }
    
    return 0;
}

你可能感兴趣的:(ITSA [C_SO41-中] 撲克牌排序)