https://www.cnblogs.com/remlostime/archive/2012/11/23/2784202.html
题目描述:
LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定去买体育彩票,嘿嘿!!“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....LL不高兴了,他想了想,决定大\小 王可以看成任何数字,并且A看作1,J为11,Q为12,K为13。上面的5张牌就可以变成“1,2,3,4,5”(大小王分别看作2和4),“So Lucky!”。LL决定去买体育彩票啦。
现在,要求你使用这幅牌模拟上面的过程,然后告诉我们LL的运气如何。为了方便起见,你可以认为大小王是0。
输入:
输入有多组数据。
每组数据包含两行,第一行输入一个正数n(0<=n<=14),表示从扑克牌中抽出的扑克牌数。接下来的一行输入n个数,表示从这幅扑克牌中抽出的牌。如果n=0,则结束输入。
输出:
对应每组数据,如果抽出的牌是顺子,则输出“So Lucky!”。否则,输出“Oh My God!”。
样例输入:
5 3 5 1 0 4 5 3 5 4 7 6 5 3 5 7 4 8 0
样例输出:
So Lucky! So Lucky! Oh My God! 先排序,然后统计0的个数,然后在统计其他数字的间隔,如果0个个数大于其他数字的间隔则可以,否则不行,另外如果有相同的数字则肯定没有顺子了。
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
int a[15];
while(cin >> n)
{
if (n == 0)
break;
for(int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int kingCount = 0;
int index = 0;
while(index < n && a[index] == 0)
{
kingCount++;
index++;
}
int count = 0;
bool same = false;
for(int i = index + 1; i < n; i++)
if (a[i] == a[i-1])
{
same = true;
break;
}
else
count += a[i] - a[i-1] - 1;
if (same || kingCount < count)
cout << "Oh My God!" << endl;
else
cout << "So Lucky!" << endl;
}
}