T1题解

· · 题解

这个思路很完美,对年龄较低的选手十分友好

很多人都用的mapset,但是我在比赛的时候却意外琢磨出了另外一种解法,先放上代码,再一一讲解

#include <bits/stdc++.h>
using namespace std;
int main(){
  //freopen("poker.in","r",stdin);
  //freopen("poker.out","w",stdout);
    int n;
    cin >> n;
    int ans = 52 - n;
    char a[10001];
    char b[10001];
    string s;
    for(int i = 0;i <= n-1;++i){
        cin >> s;
        a[i] = s[0];
        b[i] = s[1];
    }
    for(int i = 0;i <= n-1;++i){
        for(int j = i + 1;j <= n;++j){
            if(a[i] == a[j] && b[i] == b[j]){
                ++ans;
                break;
            }
        }
    }
    cout << ans;
    return 0;
}

我解释一下,char类型的a数组是用来存储每个牌花色的,而b数组是存储牌面的

紧接着一个双重for循环,此处的i必须为0,因为string类型下标的第一项是0,然后看判断的条件:我们以第一张牌的花色和数字为基准,依次往后枚举,如果有花色和基准花色一致的话,继续判断并且数字也要一致,然后让ans++,我解释一下为什么让ans自增:可以看到有一行代码是ans = 52 - n;我们首先不看重复,直接减去,然后在判断,如果有重复的让他自增,可以达到ans--再减n

谢谢,本蒟蒻第一篇题解,请认准原创