首页 > 其他 > 详细

扑克牌顺子问题

时间:2014-04-08 23:49:57      阅读:688      评论:0      收藏:0      [点我收藏+]
#include "stdafx.h"
#include "iostream"
#include <set>
#include <vector>
using namespace std;

void GetMaxMin(const set<int> & setNum, int &nMax, int &nMin)
{
	nMin = 13;
	nMax = 1;
	set<int>::const_iterator iter = setNum.begin();
	for (; iter != setNum.end();iter ++)
	{
		if(*iter < nMin)
			nMin = *iter;
		if(*iter > nMax)
			nMax = *iter;
	}
}
int Del0Num(set<int> & setNum,const vector<int>& data)
{
	int Num0 = 0;
	vector<int >::const_iterator iter = data.begin();
	for (; iter != data.end();iter ++)
	{
		if(*iter != 0)
			setNum.insert(*iter);
		else 
			Num0++;
	}
	return Num0;
}

bool IsContinuous(vector <int> data)
{
	int nMax = 0, nMin = 0;
	set<int> setNum;
	int num0 = Del0Num(setNum, data);
	if (num0 + setNum.size() < data.size())
	{
		return false;
	}
	GetMaxMin(setNum,nMax,nMin);
	return nMax - nMin <=(int) (data.size())-1;
}


int _tmain(int argc, _TCHAR* argv[])
{
	vector<int> vec;
	for (int i = 0; i < 5; i ++)
	{
		int temp;
		cin>>temp;
		vec.push_back(temp);
	}
	cout<<IsContinuous(vec)<<endl;
	return 0;
}

扑克牌顺子问题,布布扣,bubuko.com

扑克牌顺子问题

原文:http://blog.csdn.net/gaoxiangky/article/details/23203605

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!