LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定去买体育彩票,嘿嘿!!“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....LL不高兴了,他想了想,决定大\小 王可以看成任何数字,并且A看作1,J为11,Q为12,K为13。上面
// test20.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<string.h>
#include<deque>
using namespace std;
class Solution {
public:
bool IsContinuous(vector<int> numbers) {
int min = 0, max = 0, count_0 = 0;
for (int i = 0;i < numbers.size();++i)
{
if (numbers[i] == 0)
{
++count_0;
continue;
}
else
{
if (min == 0)
min = numbers[i];
else if (min > numbers[i])
min = numbers[i];
else {}
if (max == 0)
max = numbers[i];
else if (max < numbers[i])
max = numbers[i];
else{}
}
}
if (count_0 == 4) return true;
if (max == min) return false;
if (max - min>4) return false;
return true;
}
};
int main()
{
Solution so;
vector<int> numbers = { 1,2,3,4,5 };
/* bool result=so.IsContinuous(numbers);
cout <<"result:"<< result << endl;*/
bool result = so.IsContinuous(numbers);
cout << "result:" << result << endl;
cout << endl;
return 0;
}
// test20.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<string.h>
#include<deque>
using namespace std;
class Solution {
public:
bool IsContinuous(vector<int> numbers) {
int min = 0, max = 0, count_0 = 0;
for (int i = 0;i < numbers.size();++i)
{
if (numbers[i] == 0)
{
++count_0;
continue;
}
else
{
if (min == 0)
min = numbers[i];
else if (min > numbers[i])
min = numbers[i];
else {}
if (max == 0)
max = numbers[i];
else if (max < numbers[i])
max = numbers[i];
else{}
}
}
if (count_0 == 4) return true;
if (max == min) return false;
if (max - min>4) return false;
return true;
}
};
int main()
{
Solution so;
vector<int> numbers = { 1,2,3,4,5 };
/* bool result=so.IsContinuous(numbers);
cout <<"result:"<< result << endl;*/
bool result = so.IsContinuous(numbers);
cout << "result:" << result << endl;
cout << endl;
return 0;
}