c语言跳马问题

c语言跳马问题,第1张

#include<stdio.h>

#include<stdlib.h>

typedef struct node{

int x, y

struct node *nextStep

}stepNode

stepNode *q

stepNode* arrProcess[100]

int count = 0

int func(int, int, stepNode*)

int main(){

int destX, destY

int i, flag

stepNode *p

printf("请输入要到达点的坐标(0<x<9, 0<y<5):")

scanf("%d%d", &destX, &destY)

flag = func(destX, destY, NULL)

if(flag == 0){

printf("亲,跳不到点(%d,%d)哟!\n", destX, destY)

}else{

printf("共有%d种走法\n", count)

for(i=0i<counti++){

printf("第%d中方法:\n", i+1)

for(p=arrProcess[i]p!=NULLp=p->nextStep) printf("(%d,%d)\t", p->x, p->y)

printf("\n")

}

}

}

int func(int x, int y, stepNode *p){

int flag1, flag2, flag3, flag4

if(x<0 || x>8 || y<0 || y>4) return 0

q = (stepNode*)malloc(sizeof(stepNode))

q->x = x

q->y = y

q->nextStep = p

p = q

if(x==0 &&y==0){

arrProcess[count++] = q

return 1

}

flag1 = func(x-1, y-2, p)

flag2 = func(x-2, y-1, p)

flag3 = func(x-2, y+1, p)

flag4 = func(x-1, y+2, p)

if(flag1+flag2+flag3+flag4 == 0){

free(p)

return 0

}else{

return 1

}

return 0

}

供参考

你所说的句子是指的字符串吧, C语言中字符串是用字符数组来表示的.

#include<stdio.h>

#include<string.h>

int main(){

  char s[20]

  gets(s)

  if(strcmp(s, "hello world")==0)//如果输入的是字符串"hello world"

    printf("right\n")

  else

    printf("wrong\n")

  return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11506486.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存