zoukankan      html  css  js  c++  java
  • [jobdu]扑克牌顺子

    一开始看到题还以为要DFS还是BFS,后来发现完全不用。排个序,然后看看大小王能不能弥补缺口就行,但后来又发现还要排除有相同大小牌的情况。

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
     
    int main() {
        int n;
        while (cin >> n && n != 0) {
            vector<int> cards;
            int kingCount = 0;
            while (n--) {
                int x;
                cin >> x;
                if (x == 0) {
                    kingCount++;
                }
                else {
                    cards.push_back(x);
                }
            }
            sort(cards.begin(), cards.end());
            bool lucky = true;
            for (int i = 1; i < cards.size(); i++) {
                if (cards[i] == cards[i-1]) {
                    lucky = false;
                }
                kingCount -= cards[i] - cards[i-1] - 1;
                if (kingCount < 0) {
                    lucky = false;
                }
            }
            if (lucky) {
                cout << "So Lucky!" << endl;
            }
            else {
                cout << "Oh My God!" << endl;
            }
        }
    }
    

      

  • 相关阅读:
    py笔记之循环结构
    PY学习记录#5
    PY学习记录#4
    py笔记之选择结构
    PY学习记录#3
    分享一个可以随时随地写代码的工具
    PY学习记录#2
    日记啊
    Tarjan学习笔记
    Docker commands
  • 原文地址:https://www.cnblogs.com/lautsie/p/3405581.html
Copyright © 2011-2022 走看看