亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

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

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

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

绿春县| 城口县| 墨脱县| 东兴市| 藁城市| 应用必备| 怀柔区| 浮山县| 玉环县| 黄山市| 乌拉特后旗| 淅川县| 罗定市| 乌兰浩特市| 浮山县| 砚山县| 大田县| 清徐县| 桐柏县| 个旧市| 襄汾县| 竹山县| 班戈县| 宁化县| 茌平县| 临高县| 读书| 江西省| 玉树县| 许昌县| 夹江县| 山西省| 张家口市| 万荣县| 喀喇| 杂多县| 双城市| 潜江市| 汪清县| 潞城市| 刚察县|