CSP-J T1 poker

基本思路

首先我没有用 STL,只用了数组。

当然 STL 肯定会更简洁,推荐学一下。

这里我使用了一个布尔型二维数组 f[5][20] 来存对应花色是否有此点数,用函数 zhn 转换扑克牌的点数。

代码实现

#include <bits/stdc++.h>
using namespace std;
int n, cnt;
bool f[5][20];
// 第一维是花色,第二维是点数
int zhn(char x){ // 按题意转换点数
    if('2' <= x && x <= '9') return x - '0';
    if(x == 'A') return 1;
    if(x == 'T') return 10;
    if(x == 'J') return 11;
    if(x == 'Q') return 12;
    if(x == 'K') return 13;
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        char c1, c2;
        cin >> c1 >> c2;
        if(c1 == 'D') f[1][zhn(c2)] = 1;
        else if(c1 == 'C') f[2][zhn(c2)] = 1;
        else if(c1 == 'H') f[3][zhn(c2)] = 1;
        else if(c1 == 'S') f[4][zhn(c2)] = 1;
    }
    /*遍历扑克牌*/
    for(int i = 1; i <= 4; i++){
        for(int j = 1; j <= 13; j++){
            if(!f[i][j]) cnt++; // 没有就需要补
        }
    }
    cout << cnt;
    return 0;
}
posted @   KukCair  阅读(6)  评论(0编辑  收藏  举报
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示