結果

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

テストケース

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

ソースコード

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