玄关求调,麻烦大佬帮我看看错在哪里?
  • 板块学术版
  • 楼主封禁用户
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/5/11 22:18
  • 上次更新2024/5/12 09:49:37
查看原帖
玄关求调,麻烦大佬帮我看看错在哪里?
668156
封禁用户楼主2024/5/11 22:18
#include <iostream>
#include <string>

using namespace std;

int canWin(string hand) {
    int count[128] = {0};
    for (char c : hand) {
        count[c]++;
    }

    int res = 0;
    for (char c = '1'; c <= '9'; c++) {
        if (count[c] < 4) {
            count[c]++;
            bool win = true;

            for (char i = '1'; i <= '9'; i++) {
                if (count[i] >= 3) {
                    count[i] -= 3;
                }
                else if (count[i] == 2) {
                    count[i] -= 2;
                }
                else if (count[i] == 1) {
                    count[i]--;
                }
                else {
                    win = false;
                    break;
                }
            }

            for (char i = '1'; i <= '9'; i++) {
                if (count[i] % 2 != 0) {
                    win = false;
                    break;
                }
            }

            string yaoji = "19zESWN";
            for (char y : yaoji) {
                if (count[y] == 0) {
                    win = false;
                    break;
                }
            }

            if (win) {
                res++;
            }

            count[c]--;
        }
    }

    return res;
}

int main() {
    string hand;
    cin >> hand;

    int result = canWin(hand);
    cout << result << endl;

    return 0;
}
2024/5/11 22:18
加载中...