91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C語言怎么實現發牌洗牌

發布時間:2022-05-05 10:14:12 來源:億速云 閱讀:146 作者:iii 欄目:開發技術

本文小編為大家詳細介紹“C語言怎么實現發牌洗牌”,內容詳細,步驟清晰,細節處理妥當,希望這篇“C語言怎么實現發牌洗牌”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

1.模擬發牌程序

通過寫兩個函數模塊來編寫洗牌程序和打印的發牌程序

2.編寫洗牌程序

void shuffle(char cards[][10],int n){
    int i=54;
    char ca,cb,ct[10];
    srand((unsigned)time(NULL));
    
    while(i--){
        ca=rand()%54;
        cb=rand()%54;
        
        strcpy(ct,cards[ca]);
        strcpy(cards[ca],cards[cb]);
        strcpy(cards[cb],ct);        
    }
        
}

3.編寫打印的發牌程序

void printCard(char cards[][10],int n){
    int i,rn=0;
    printf("第一個人:\n");
    for(i=0;i<17;i++){
        if(rn%5==0)
            printf("\n");
        rn++;
        printf("%s      ",cards[i]);        
    }
    printf("\n\n第二個人:\n");
    rn=0;
    for(i=17;i<33;i++){
        if(rn%5==0)
            printf("\n");
        rn++;
        printf("%s      ",cards[i]);        
    }
    printf("\n\n第三個人:\n");
    rn=0;
    for(i=33;i<50;i++){
        if(rn%5==0)
            printf("\n");
        rn++;    
        printf("%s      ",cards[i]);    
    }
    printf("\n\n底牌:\n");
    for(i=51;i<54;i++){
        printf("%s      ",cards[i]);        
    }
    printf("\n");
    getchar();
}

4.在主函數預定義和調用

main(){
    system("color 0f");
    char cards[][10]={
    "紅桃 2","紅桃 3","紅桃 4","紅桃 5","紅桃 6","紅桃 7","紅桃 8","紅桃 9","紅桃 10","紅桃 J","紅桃 Q","紅桃 K","紅桃 A",
    "方塊 2","方塊 3","方塊 4","方塊 5","方塊 6","方塊 7","方塊 8","方塊 9","方塊 10","方塊 J","方塊 Q","方塊 K","方塊 A",
    "梅花 2","梅花 3","梅花 4","梅花 5","梅花 6","梅花 7","梅花 8","梅花 9","梅花 10","梅花 J","梅花 Q","梅花 K","梅花 A",        
    "黑桃 2","黑桃 3","黑桃 4","黑桃 5","黑桃 6","黑桃 7","黑桃 8","黑桃 9","黑桃 10","黑桃 J","黑桃 Q","黑桃 K","黑桃 A",
    "大王","小王" 
    };
    int n = 54;
 
    shuffle(cards,n);
    printCard( cards, n);
        
return 0;
}

5.最終程序

#include<stdio.h>
#include<string.h>
#include<stdlib.h> 
#include<time.h>
void shuffle(char cards[][10],int n);
void printCard(char cards[][10],int n);

main(){
    system("color 0f");
    char cards[][10]={
    "紅桃 2","紅桃 3","紅桃 4","紅桃 5","紅桃 6","紅桃 7","紅桃 8","紅桃 9","紅桃 10","紅桃 J","紅桃 Q","紅桃 K","紅桃 A",
    "方塊 2","方塊 3","方塊 4","方塊 5","方塊 6","方塊 7","方塊 8","方塊 9","方塊 10","方塊 J","方塊 Q","方塊 K","方塊 A",
    "梅花 2","梅花 3","梅花 4","梅花 5","梅花 6","梅花 7","梅花 8","梅花 9","梅花 10","梅花 J","梅花 Q","梅花 K","梅花 A",        
    "黑桃 2","黑桃 3","黑桃 4","黑桃 5","黑桃 6","黑桃 7","黑桃 8","黑桃 9","黑桃 10","黑桃 J","黑桃 Q","黑桃 K","黑桃 A",
    "大王","小王" 
    };
    int n = 54;
 
    shuffle(cards,n);
    printCard( cards, n);
        
return 0;
}

void shuffle(char cards[][10],int n){
    int i=54;
    char ca,cb,ct[10];
    srand((unsigned)time(NULL));
    
    while(i--){
        ca=rand()%54;
        cb=rand()%54;
        
        strcpy(ct,cards[ca]);
        strcpy(cards[ca],cards[cb]);
        strcpy(cards[cb],ct);        
    }
        
}

void printCard(char cards[][10],int n){
    int i,rn=0;
    printf("第一個人:\n");
    for(i=0;i<17;i++){
        if(rn%5==0)
            printf("\n");
        rn++;
        printf("%s      ",cards[i]);        
    }
    printf("\n\n第二個人:\n");
    rn=0;
    for(i=17;i<33;i++){
        if(rn%5==0)
            printf("\n");
        rn++;
        printf("%s      ",cards[i]);        
    }
    printf("\n\n第三個人:\n");
    rn=0;
    for(i=33;i<50;i++){
        if(rn%5==0)
            printf("\n");
        rn++;    
        printf("%s      ",cards[i]);    
    }
    printf("\n\n底牌:\n");
    for(i=51;i<54;i++){
        printf("%s      ",cards[i]);        
    }
    printf("\n");
    getchar();
}

6.1程序結果

C語言怎么實現發牌洗牌

6.2

C語言怎么實現發牌洗牌

讀到這里,這篇“C語言怎么實現發牌洗牌”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

东乡县| 高密市| 松江区| 保山市| 农安县| 景德镇市| 昭觉县| 天峻县| 宜君县| 阿坝| 重庆市| 延长县| 德庆县| 翼城县| 宝鸡市| 庐江县| 吴旗县| 清河县| 宿松县| 山阳县| 奇台县| 泉州市| 中方县| 北海市| 中江县| 礼泉县| 广宁县| 大关县| 册亨县| 大埔县| 上栗县| 太和县| 涞水县| 辽阳县| 论坛| 中超| 吴川市| 淳安县| 佛教| 高淳县| 涿州市|