7、 猴子选大王**
来源:百度知道 编辑:UC知道 时间:2024/05/22 05:17:03
要求:
输入数据:输入m,n,为整数,n<m
输出形式:中文提示按照m个猴子,数n个数的方法,输出为大王的猴子是几号,建立一个函数来实现此功能.
谢谢,希望大哥会做的帮小妹一下.
#include<stdio.h>
#include<stdlib.h>
struct listNode{
int data;
struct listNode *nextPtr;
};
typedef struct listNode LISTNODE;
typedef LISTNODE * LISTNODEPTR;/*LISTNODEPTR:指向LISTNODE指针*/
void printList(LISTNODEPTR currentPtr);/*打印链表*/
void destroyList(LISTNODEPTR headPtr);/*释放链表各个结点*/
LISTNODEPTR createList(int n);
void selectKing(LISTNODEPTR headPtr1,int n);
int main(int argc, char *argv[])
{
LISTNODEPTR headPtr1=NULL,headPtr2=NULL;
int count,monkeys;
int n;
printf("input the amount of monkeys:");
scanf("%d",&monkeys); /*猴子个数*/
printf("input the count number:");
scanf("%d",&count); /*count=3,表示每次数到3的猴子出局*/
headPtr1=createList(monkeys);/*创建循环链表*/
selectKing(headPtr1,count);/*选大王。headPtr1指向循环链表。headPtr2指向由淘汰猴子组成地链表*/
system("P