0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ポーカー

Last updated at Posted at 2015-02-25
Source.cpp
#include "Header.h"

const int&	Poka::checkSamaCard()
{
	int sameCards =0;
	for(int i=0; i<HAND; i++){
		for(int j=0; j<HAND; j++){
			m_numbers.at(i) == m_numbers.at(j) ? sameCards++ : sameCards;
		}
	}
	return sameCards;
}

const std::string Poka::checkRank()
{
	const int sameCards = checkSamaCard();
	if( sameCards == 17 )
		return "4K";
	if( sameCards == 13 )
		return "FH";
	if( sameCards == 11 )
		return "3K";
	if( sameCards == 9 )
		return "2P";
	if( sameCards == 7 )
		return "1P";

	return "--";
}

void Poka::getNumbers(std::string input)
{
	int index = 0;
	for(int i=0; i<HAND; i++){
		index = input.find_first_of("SHDC",index) +1;
		m_numbers.push_back(input.substr(index, 1));
	}
}

const std::string Poka::solve(const std::string& input)
{
	getNumbers(input);
	const std::string& rank = checkRank();
	return rank;
}

int main()
{
	const std::string input = "S8D10H10S10C10";
	Poka poka;
	std::cout << poka.solve(input) << std::endl;
	return 0;
}
Source.h
#ifndef _HEADER_H
#define _HEADER_H

#include <string>
#include <iostream>
#include <vector>

#define HAND 5

class Poka
{
public:
	const std::string			solve(const std::string& input);
private:
	const int&					checkSamaCard();
	const std::string			checkRank();
	void						getNumbers(std::string input);
	std::vector<std::string>	m_numbers;//10は1とする。
};

#endif
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?