- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我都试过了!我应该添加皇家同花顺部分。我了解同花顺、同花顺和同花顺部分,但我似乎无法理解皇家同花顺部分。最后,代码应该打印出 50000 张牌中有多少张顺子、同花顺、同花顺和皇家同花顺。这开始是我与合作伙伴的实验室,但现在为了获得额外的荣誉,我应该添加皇家同花顺部分,但我一无所知。提前致谢。
#include <stdio.h>
#define SIZE 50000
typedef struct card_t_struct{
int value; // 1 through 13
int suit; // 0 is clubes, 1 is diamonds, 2 is spades, 3 is hearts
} card_t;
void printCard(card_t card){
if(card.value == 1){
printf("Ace");
}else if(card.value == 11){
printf("Jack");
}else if(card.value == 12){
printf("Queen");
}else if(card.value == 13){
printf("King");
}else{
printf("%d", card.value);
}
printf(" of ");
if(card.suit == 0){
printf("Clubs.");
}else if(card.suit == 1){
printf("Diamonds.");
}else if(card.suit == 2){
printf("Spades.");
}else if(card.suit == 3){
printf("Hearts.");
}else{
printf("%d not a suit", card.suit); // Error message
}
printf("\n");
}
void hand(card_t* a){
int i = 0;
for(i = 0; i < 5; i++){
printCard(a[i]);
}
}
void shuffle(card_t* array, int length){
int i = 0;
for(i = 0; i < length * 2; i++){
int from = rand() % length;
int to = rand() % length;
card_t temp = array[from];
array[from] = array[to];
array[to] = temp;
}
}
void bubble(card_t* f, int length){
int i = 0;
int bub_num = 0;
for(bub_num = 0; bub_num < length; bub_num++){
for(i = 0; i < length - 1; i++){
if(f[i].value > f[i+1].value){ // Wrong order
int temp = f[i].value;
f[i].value = f[i+1].value;
f[i+1].value = temp;
}else{
}
}
}
}
int isFlush(card_t* deck){
int i = 0;
for(i = 1; i < 5; i++){
if(deck[i].suit != deck[0].suit){
return 0;
}
}
return 1;
}
int isStraight(card_t* deck){
int i = 0;
for(i = 1; i < 5; i++){
if(deck[i+1].value != deck[i].value + 1){
return 0;
}
}
return 1;
}
int isSFlush(card_t* deck){
int i = 0;
for(i = 1; i < 5; i++){
if(deck[i+1].value != deck[i].value + 1){
return 0;
}
}
for(i = 1; i < 5; i++){
if(deck[i].suit != deck[0].suit){
return 0;
}
}
return 1;
}
int isRFlush(card_t* deck){
int i = 0;
for(i = 1; i < 5; i++){
if(deck[i].value != deck[i].value){
return 0;
}
}
for(i = 1; i < 5; i++){
if(deck[i].suit != deck[0].suit){
return 0;
}
}
return 1;
}
int main(){
srand(time(0));
card_t deck[52] = {};
int i = 0;
int flush = 0;
int straight = 0;
int straight_flush = 0;
int royal_flush = 0;
int suit = 0;
for(suit = 0; suit < 4; suit++){
int value = 1;
for(value = 1; value <= 13; value++){
deck[i].suit = suit;
deck[i].value = value;
i++;
}
}
for(i = 0; i < SIZE; i++){
shuffle(deck, 52);
hand(deck);
if(isFlush(deck) ){
flush++;
}
printf("\n");
bubble(deck, 5);
if(isStraight(deck) ){
straight++;
}
if(isSFlush(deck) ){
straight_flush++;
}
if(isRFlush(deck) ){
royal_flush++;
}
}
printf("The number of flushes you have is: %d\n", flush);
printf("The number of straights you have is: %d\n", straight);
printf("The number of straight flushes you have is: %d\n", straight_flush);
printf("The number of royal flushes you have is: %d\n", royal_flush);
}
最佳答案
基于现有的IsStraight(...)
函数,我假设你的 isRFlush(...)
函数正在传递一张五张牌(不是一副牌),其牌是按升序排列的?
int isRFlush(card_t* deck) {
int i = 0; // zero-based index into your hand of five cards (0-4)
// This next bit DOESN'T ACTUALLY DO ANYTHING. The reason is that comparing anything
// with itself will always result in an equality (i.e. 1==1, 3.14==3.14, a==a, etc),
// so this comparison always returns false, and the return 0 after the if statement
// is never taken, regardless of the value of the cards passed in.
/*
for (i = 1; i < 5; i++) {
if (deck[i].value != deck[i].value) { // <--- Never false, no matter what
return 0;
}
}
*/
// What the other isXxxx methods above were doing was ensuring that each 'next' card
// was 'one higher' than the card that came before it in the hand. If that's found to
// be untrue for any card in the hand, then the function exits with a zero.
//
// That's the logic for a STRAIGHT, but we're looking for a ROYAL STRAIGHT, so the
// hand HAS to be "10 J Q K A" (all of the same suit, but we'll check that part later).
//
// Since the Ace represents a non-sequential value, I think you may as well just do
// this using five comparisons without the loop:
if ( deck[0].value != 1 // if 1st card isn't Ace
|| deck[1].value != 10 // or 2nd card isn't 10
|| deck[2].value != 11 // or 3rd card isn't Jack
|| deck[3].value != 12 // or 4th card isn't Queen
|| deck[4].value != 13) { // or 5th card isn't King
return 0; // Not a royal straight
}
// If we've made it this far, we know that we have a ROYAL STRAIGHT (e.g. 10, J, Q, K, A)
// Now, we need to ensure that we also have a FLUSH
// Loop through the 2nd to last cards, ensuring they are all
// of the same suit as the first card in the hand
for (i = 1; i < 5; i++) {
if (deck[i].suit != deck[0].suit) {
return 0; // Not a flush
}
}
return 1; // This hand IS a Royal Straight Flush (aka Royal Flush)
}
最后的注释:
此程序中可能还有其他错误。例如,isStraight(...)
跳过第一张卡片并循环遍历最后四张卡片,但它正在向索引 i
添加一个什么时候应该减一:
// Note: This function doesn't recognize a non-sequential "ace-high" flush
// (e.g. 10,J,Q,K,A).
int isStraight(card_t* deck) {
int i = 0;
for (i = 1; i < 5; i++) {
// Loop values of i will be [1, 2, 3, 4], which correspond to the 2nd through 5th card in the hand passed in.
// To check these against the previous card, you should subtract one (vs adding one).
/*
if (deck[i+1].value != deck[i].value + 1) { // <--- Array Index Out Of Bounds
*/
// If card in hand isn't 'one higher' than the previous card...
if (deck[i-1].value != deck[i].value + 1) {
return 0;
}
}
return 1;
}
由于您已经有一个检查手牌是否齐平的函数,您可以通过在 isRFlush(...)
中调用它来利用它来节省一些输入。功能:
int isRFlush(card_t* deck) {
if ( deck[0].value != 1 // if 1st card isn't Ace
|| deck[1].value != 10 // or 2nd card isn't 10
|| deck[2].value != 11 // or 3rd card isn't Jack
|| deck[3].value != 12 // or 4th card isn't Queen
|| deck[4].value != 13) { // or 5th card isn't King
return 0; // Not a royal straight
}
// At this point, you know it's a ROYAL STRAIGHT, so just return whether or not it's also
// a FLUSH
return isFlush(deck);
}
关于c - 皇家同花顺不适用于手牌分配 [C],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49929623/
我在我的 Xcode 项目目录中输入了以下内容: keytool -genkey -v -keystore release.keystore -alias mykey -keyalg RSA \
假设我有一个像这样的 DataFrame(或 Series): Value 0 0.5 1 0.8 2 -0.2 3 None 4 None 5 None
我正在对一个 Pandas 系列进行相对繁重的应用。有什么方法可以返回一些打印反馈,说明每次调用函数时在函数内部进行打印还有多远? 最佳答案 您可以使用跟踪器包装您的函数。以下两个示例,一个基于完成的
我有一个 DataFrame,其中一列包含列表作为单元格内容,如下所示: import pandas as pd df = pd.DataFrame({ 'col_lists': [[1, 2
我想使用 Pandas df.apply 但仅限于某些行 作为一个例子,我想做这样的事情,但我的实际问题有点复杂: import pandas as pd import math z = pd.Dat
我有以下 Pandas 数据框 id dist ds 0 0 0 0 5 1 0 0 7 2 0 0
这发生在我尝试使用 Gradle 构建时。由于字符串是对象,因此似乎没有理由发生此错误: No signature of method: java.util.HashMap.getOrDefault(
您好,有人可以解释为什么在 remaining() 函数中的 Backbone 示例应用程序 ( http://backbonejs.org/examples/todos/index.html ) 中
我有两个域类:用户 class User { String username String password String email Date dateCreated
问题陈述: 一个 pandas dataframe 列系列,same_group 需要根据两个现有列 row 和 col 的值从 bool 值创建。如果两个值在字典 memberships 中具有相似
apporable 报告以下错误: error: unknown type name 'MKMapItem'; did you mean 'MKMapView'? MKMapItem* destina
我有一个带有地址列的大型 DataFrame: data addr 0 0.617964 IN,Krishnagiri,635115 1 0.635428 IN,Chennai
我有一个列表list,里面有这样的项目 ElementA: Number=1, Version=1 ElementB: Number=1, Version=2 ElementC: Number=1,
我正在编译我的源代码,它只是在没有运行应用程序的情况下终止。这是我得到的日志: Build/android-armeabi-debug/com.app4u.portaldorugby/PortalDo
我正在尝试根据另一个单元格的值更改单元格值(颜色“红色”或“绿色”)。我运行以下命令: df.loc[0, 'Colour'] = df.loc[0, 'Count'].apply(lambda x:
我想弄清楚如何使用 StateT结合两个 State基于对我的 Scalaz state monad examples 的评论的状态转换器回答。 看来我已经很接近了,但是在尝试申请 sequence
如果我已经为它绑定(bind)了集合,我该如何添加 RibbonLibrary 默认的快速访问项容器。当我从 UI 添加快速访问工具项时,它会抛出 Operation is not valid whi
在我学习期间Typoclassopedia我遇到了这个证明,但我不确定我的证明是否正确。问题是: One might imagine a variant of the interchange law
我是一名优秀的程序员,十分优秀!