| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2437 人关注过本帖
标题:华容道代码
取消只看楼主 加入收藏
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
结帖率:62.5%
收藏
已结贴  问题点数:20 回复次数:1 
华容道代码
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
int c=0,a[8][8]= {0},n=0,x,y,b[8][8]= {0};
int t=0;
int main() {
T1:
   
    system("color 0f");
    srand(time(0));
    printf("¡ö                    ¡ö¡î2½    êy£o%d\n¡ö                    ¡ö¡î2ù×÷·½·¨£o\n¡ö                    ¡ö¡îêäèëêy×Öòƶˉ»¬¿é,3~6Ñ¡ÔñÄѶè \n¡ö                    ¡ö¡î1Ø    óú£o\n¡ö                    ¡ö¡î»aèYμàV1.0\n¡ö                    ¡ö¡î×÷Õߣo¸ù¸ù±¾¸ù\n",c);
    printf("¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î");
    printf("¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î\n");
    scanf("%d",&n);
    if(n==0) {
        return 0;
    }

    for(int i=1; i<n*n; i++) {
        y=rand()%n+1;
        x=rand()%n+1;
        if(a[x][y]!=0) {
            i--;
        } else {
            a[x][y]=i;
        }
    }
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            printf("%2d ",a[i][j]);

        }
        printf("\n");
    }
    while(t==0) {
        int v=0,st=n*n;
        char e;
        e=getch();

        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(a[i][j]==0) {
                    switch(e) {//up=72,down=80,right=77,left=75
                        case 72:
                            a[i][j]=a[i+1][j];
                            a[i+1][j]=0;
                            break;
                        case 80:
                            a[i][j]=a[i-1][j];
                            a[i-1][j]=0;
                            break;
                        case 75:
                            a[i][j]=a[i][j+1];
                            a[i][j+1]=0;
                            break;
                        case 77:
                            a[i][j]=a[i][j-1];
                            a[i][j-1]=0;
                            break;
                    }
                    v=1;
                    break;
                }
            }
            if(v) {
                break;
            }
        }
//        if(a[x+1][y]==0) {
//            a[x+1][y]=e;
//            a[x][y]=0;
//        } else if(a[x][y+1]==0) {
//            a[x][y+1]=e;
//            a[x][y]=0;
//        } else if(a[x-1][y]==0) {
//            a[x-1][y]=e;
//            a[x][y]=0;
//        } else if(a[x][y-1]==0) {
//            a[x][y-1]=e;
//            a[x][y]=0;
//        }
        c++;
        system("cls");
        printf("¡ö                    ¡ö¡î2½    êy£o%d\n¡ö                    ¡ö¡î2ù×÷·½·¨£o\n¡ö                    ¡ö¡îêäèëêy×Öòƶˉ»¬¿é,3~6Ñ¡ÔñÄѶè \n¡ö                    ¡ö¡î1Ø    óú£o\n¡ö                    ¡ö¡î»aèYμàV1.0\n¡ö                    ¡ö¡î×÷Õߣo¸ù¸ù±¾¸ù\n",c);
        printf("¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î");
        printf("¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î\n");
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {

                printf("%2d ",a[i][j]);
            }
            printf("\n");
        }
        if(a[n][n]!=0) {
            continue;
        }
        t=1;
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(a[i][j]!=(i-1)*n+j&&(i!=n||j!=n)) {
                    t=0;
                    break;
                }
            }
            if(t==0) {
                break;
            }
        }
    }
    system("cls");
    printf("1§Ï2ÄãÄãóÃáË%d2½íê3éáË%d½×»aèYμ࣡\nÏëÔùà′ò»¾Ö°′¿Õ¸ñ\n",c/2,n);
    char z=getchar();
    if(z==' ') {
        system("cls");
        goto T1;
    }
    Sleep(3000);
    return 0;
}
搜索更多相关主题的帖子: int printf for i++ break 
2018-03-29 21:26
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
收藏
得分:0 
严禁抄袭!!
2018-03-29 21:32
快速回复:华容道代码
数据加载中...
 
   



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

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