• C语言实现字母接龙的小程序


    代码
    #include<stdio.h>
    #include
    <stdlib.h>
    #include
    <time.h>
    main()
    {
    int i,j,c,flag,sign,counter;
    int array[10][10],area,x,y;
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    array[i][j]
    =46;
    for(i=0;i<10;i++)
    {
    for(j=0;j<10;j++)
    printf(
    "%c",array[i][j]);
    printf(
    "\n");
    }
    srand((unsigned)time(NULL));
    printf(
    "Notion!While the value of x and y less than 10 and positive integret,\n"
    "Please the beginning place of the game (x,y):");
    scanf(
    "%d,%d",&x,&y);
    array[x][y]
    =65;
    for(c=66;c<=90;c++)
    {
    do
    {
    counter
    =rand()%4;
    switch(counter)
    {
    case 0: /* Moving toward right*/
    {
    if(array[x][y+1]==46&&y+1<10)
    {
    array[x][
    ++y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }

    /* Moving toward down*/
    case 1:
    {
    if(array[x+1][y]==46&&x+1<10)
    {
    array[
    ++x][y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }
    /* Moving toward left*/
    case 2:
    {
    if(array[x][y-1]==46&&y-1>0)
    {
    array[x][
    --y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }
    /* Moving toward up*/
    case 3:
    {
    if(array[x-1][y]==46&&x-1>0)
    {
    array[
    --x][y]=c;
    flag
    =1;
    break;
    }
    else
    {
    flag
    =0;
    break;
    }
    }
    }
    }
    while(flag!=1);
    flag
    =0;
    sign
    =(array[x][y+1]==46||array[x][y-1]==46||array[x-1][y]==46||array[x+1][y]==46);
    if(sign==0)
    break;
    }

    for(i=0;i<10;i++)
    {
    for(j=0;j<10;j++)
    printf(
    "%c",array[i][j]);
    printf(
    "\n");
    }
    getch();
    }
  • 相关阅读:
    Ch’s gift HDU
    String HDU
    Rikka with String HDU
    DNA repair HDU
    Ring HDU
    A Secret HDU
    看详细的tomcat报错信息
    linux tomcat服务器优化配置
    linux常用命令
    关于Context []startup failed due to previous errors有效解决方式
  • 原文地址:https://www.cnblogs.com/uestc/p/1910903.html
Copyright © 2020-2023  润新知