結果

問題 No.227 簡単ポーカー
ユーザー nakapanakapa
提出日時 2018-08-26 18:20:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,842 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 65,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 19:21:17
合計ジャッジ時間 1,266 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <istream>
#include <vector>


using namespace std;

enum PokerHAND{
  FULL_HOUSE=0,
  THREE_CARD=1,
  TWO_PAIR=2,
  ONE_PAIR=3,
  NO_HAND=4
};

// input sample
// 5 6 5 6 5

int judgePoker(){

  std::string str;
  std::string buf;
  std::vector <int> deck;

//  std::cout << "Please input cards"<< std::endl;
  getline(cin, str);
//  std::cout << "Input cards: "<< str <<std::endl;

  int cnt[13] = {};
  int flg_three = 0;
  int flg_two = 0;

  int result = NO_HAND;

  std::stringstream ss{str};

  while(getline(ss, buf, ' '))
  {
    deck.push_back(std::stoi(buf));
  }
  //cout << vec[0];
  for (std::vector<int>::const_iterator i = deck.begin(); i != deck.end(); ++i)
  {
#ifdef DEBUG
    std::cout << *i << ",";
#endif
    cnt[*i-1]++;
  }
#ifdef DEBUG
  std::cout << std::endl;
#endif

  if(deck.size() != 5){
    return -1;
  }

  for (int j = 0; j<13 ;j++)
  {
#ifdef DEBUG
    std::cout <<j<< ": "<< cnt[j] << std::endl;
#endif

    if (cnt[j] == 3){
#ifdef DEBUG
      std::cout << "three: "<< j << std::endl;
#endif
      flg_three = 1;
    }
    else if (cnt[j] == 2) {
#ifdef DEBUG
      std::cout << "two: "<< j << std::endl;
#endif
      flg_two++;
    }
  }
#ifdef DEBUG
  std::cout << "flg_three: "<< flg_three << std::endl;
  std::cout << "flg_two: "<< flg_two << std::endl;
#endif
  if     (flg_three == 1 && flg_two == 1) {cout << "FULL HOUSE"<< endl;}
  else if(flg_three == 1 && flg_two == 0) {cout << "THREE CARD"<< endl;}
  else if(flg_three == 0 && flg_two == 2) {cout << "TWO PAIR"<< endl;}
  else if(flg_three == 0 && flg_two == 1) {cout << "ONE PAIR"<< endl;}
  else                                    {cout << "NO HAND"<< endl;}

  return 0;
}

int main(){

  if (judgePoker()== -1){
    std::cout << "Wrong input" << std::endl;
    return -1;
  }

  return 0;
}
0