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