| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1116 人关注过本帖
标题:各位大佬,抽卡问题怎么写啊,帮帮孩子吧!
只看楼主 加入收藏
一个小摆
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-6-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
各位大佬,抽卡问题怎么写啊,帮帮孩子吧!
目前我就写成这个样子。问题是如何将竖列的输出结果改成横向的输出结果,还有一个问题是如何覆盖上一次的抽卡
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    printf("输入1开始抽卡,输入0结束游戏");
    while (1)
    {
        int n;
        scanf("%d", &n0);
        switch (n)
        {
        case 1:
        {
            int i;
            srand((unsigned)time(NULL));
            for (i = 0; i < 5; i++)
                if (rand() % 1001 - 70 < 0)
                {
                    char u[][11] = { {' ','_','_','_','_','_','_','_','_','_',' '},
                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ',' ','*','*','*',' ',' ',' ','|'},
                              {'|','_','_','_','_','_','_','_','_','_','|'},
                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                              {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '} };
                    int e, f;
                    for (e = 0; e < 9; e++) {
                        for (f = 0; f < 11; f++)
                            printf("%c", u[e][f]);
                    printf("\n");   
                    }
                }
                else
                {
                    if (rand() % 1001 - 190 < 0)
                    {
                        char ss[][11] = { {' ','_','_','_','_','_','_','_','_','_',' '},
                                  {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                  {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                  {'|',' ','*','*',' ',' ',' ','*','*',' ','|'},
                                  {'|','*',' ',' ',' ',' ','*',' ',' ',' ','|'},
                                  {'|',' ','*','*',' ',' ',' ','*','*',' ','|'},
                                  {'|',' ',' ',' ','*',' ',' ',' ',' ','*','|'},
                                  {'|','*','*','*',' ',' ','*','*','*',' ','|'},
                                  {'|','_','_','_','_','_','_','_','_','_','|'},
                                  {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                  {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '} };
                        int g, h;
                        for (g = 0; g < 9; g++) {
                            for (h = 0; h < 11; h++)
                                printf("%c", ss[g][h]);
                            printf("\n");   
                        }
                    }
                    else
                    {
                        if (rand() % 1001 - 700 < 0)
                        {
                            char s[][12] = { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
                                              {' ','_','_','_','_','_','_','_','_','_',' '},
                                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                              {'|',' ',' ',' ','*','*','*','*',' ',' ','|'},
                                              {'|',' ',' ','*',' ',' ',' ',' ',' ',' ','|'},
                                              {'|',' ',' ',' ','*','*','*',' ',' ',' ','|'},
                                              {'|',' ',' ',' ',' ',' ',' ','*',' ',' ','|'},
                                              {'|',' ',' ','*','*','*','*',' ',' ',' ','|'},
                                              {'|','_','_','_','_','_','_','_','_','_','|'},
                                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                              {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '} };
                            int a, b;
                            for (a = 0; a < 9; a++) {
                                for (b = 0; b < 12; b++)
                                    printf("%c", s[a][b]);
                                printf("\n");   
                            }
                        }
                        else
                        {
                            char r[][12]={{' ','_','_','_','_','_','_','_','_','_',' '},
                                             {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                               {'|',' ',' ','*','*','*','*','*',' ',' ','|'},
                                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                                              {'|',' ',' ','*','*','*','*','*',' ',' ','|'},
                                              {'|',' ',' ','*','*','*',' ',' ',' ',' ','|'},
                                             {'|',' ',' ','*',' ',' ','*',' ',' ',' ','|'},
                                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                                              {'|','_','_','_','_','_','_','_','_','_','|'},
                                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                                              {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}};
                            int e, f;
                            for (e = 0; e < 9; e++) {
                                for (f = 0; f < 11; f++)
                                    printf("%c", r[e][f]);
                                printf("\n");   
                            }
                    }
                        }
                        }
                    ;
            break;
        }
        case 0:
        {
            return 0;
        }
        }
    }
}

麻烦各位大佬了,帮我看看怎么改正,谢谢了
搜索更多相关主题的帖子: printf char for int rand 
2022-06-02 14:31
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:10 
这个 rand 的用法我竟然看不懂,难道不应该调用一次吗?

还有
                    char u[][11] = { {' ','_','_','_','_','_','_','_','_','_',' '},
                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ','*',' ',' ',' ','*',' ',' ','|'},
                              {'|',' ',' ',' ','*','*','*',' ',' ',' ','|'},
                              {'|','_','_','_','_','_','_','_','_','_','|'},
                              {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
                              {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '} };
写成如下不好吗?
程序代码:
const char* u = " _________ "
                "|         |"
                "|         |"
                "|  *   *  |"
                "|  *   *  |"
                "|  *   *  |"
                "|  *   *  |"
                "|   ***   |"
                "|_________|"
                "|         |"
                "           ";
2022-06-02 15:16
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:0 
如何将竖列的输出结果改成横向的输出结果
大概猜出你想问什么了,我给你一个示例

注意:以下是纯正C代码(至少使用C11标准,最好使用C17标准),没法使用C++方式编译(代码中存在C支持,但C++不支持的语法)
程序代码:
#include <stdio.h>

const char* u  = " _________ "
                 "|         |"
                 "|  *   *  |"
                 "|  *   *  |"
                 "|  *   *  |"
                 "|  *   *  |"
                 "|   ***   |"
                 "|_________|";

const char* s  = " _________ "
                 "|         |"
                 "|   ****  |"
                 "|  *      |"
                 "|   ***   |"
                 "|      *  |"
                 "|  ****   |"
                 "|_________|";

void print_cards( const char* cards[] )
{
    enum { HEIGHT=8, WIDTH=11, INTERVAL=2 };
    for( int r=0; r!=HEIGHT; ++r )
        for( const char** p=cards; *p; ++p )
            printf( "%.*s%*s", WIDTH, &(*p)[r*WIDTH], (p[1]?INTERVAL:1), (p[1]?"":"\n") );
}

int main( void )
{
    print_cards( (const char*[]){u,s,NULL} );
    print_cards( (const char*[]){s,u,s,s,NULL} );
}


输出
程序代码:
 _________    _________
|         |  |         |
|  *   *  |  |   ****  |
|  *   *  |  |  *      |
|  *   *  |  |   ***   |
|  *   *  |  |      *  |
|   ***   |  |  ****   |
|_________|  |_________|

 _________    _________    _________    _________
|         |  |         |  |         |  |         |
|   ****  |  |  *   *  |  |   ****  |  |   ****  |
|  *      |  |  *   *  |  |  *      |  |  *      |
|   ***   |  |  *   *  |  |   ***   |  |   ***   |
|      *  |  |  *   *  |  |      *  |  |      *  |
|  ****   |  |   ***   |  |  ****   |  |  ****   |
|_________|  |_________|  |_________|  |_________|
2022-06-02 16:28
追梦人zmrghy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:406
专家分:190
注 册:2021-4-9
收藏
得分:10 
一枚小嘿,
你好,
这上在做什么呀。。。。
是不是,编辑界面,和输出界面,不一致呀???
输出行,水平位置,不对呀。。。
我也遇到过这个问题, 代码编辑界面对齐,输出界面对不齐。
没办法,只能一行,一行的调整,看输出结果。。。
最后,输出界面对齐了。。。
代码编辑界面就乱了。。。。
不清楚,什么原因。。。
2022-06-04 09:44
追梦人zmrghy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:406
专家分:190
注 册:2021-4-9
收藏
得分:0 
只要,你学习使用单片机的取模软件。
就会明白,为什么对不齐了。。。
2022-06-04 09:47
快速回复:各位大佬,抽卡问题怎么写啊,帮帮孩子吧!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019231 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved