头像-278799

大少爷安安

  • 河南省安阳市
  • 本科
  • 单片机
  • 其他

个人成就

获得 291 次赞

帮助过403人

约瑟夫环问题

#include<stdio.h>#include<stdlib.h>#define MAXPV 20         /@@*每人最大密码值为20*/#define MAXNUM 30        /@@*需要处理的最多人数为30*/#define MAXFV 10         /@@*初始查找上限值为10*/typedef struct linkList{ int data; int password; struct linkList *next;}linkList;/@@*函数声明*/linkList *CreatList();void InitList(linkList *int );int GetPassword();int GetPersonNumber();int GetFirstCountValue();void GetOutputOrder(linkList* int int int* );void printResult(int * int );linkList *CreatList(){   /@@*初始化单链表函数*/ linkList *L; L=(linkList *)malloc(sizeof(linkList)); if (L==NULL) {  printf("分配内存失败!");  exit(1); } return L;}void InitList(linkList *L int personNumber){    /@@*建立循环单链表函数*/ linkList *p*q; int i; p=L; p->data=1; p->password=GetPassword(); for (i=2; i<=personNumber; i++) {   q=(linkList *)malloc(sizeof(linkList));  if(q==NULL)  {   printf("分配内存空间失败!");   exit(1);  }  q->password=GetPassword();  q->data=i;  p->next=q;  p=q; } p->next=L;}int GetPersonNumber(){   /@@*输入处理的人数函数*/ int personNumber; printf("请输入人数:"); scanf("%d"&personNumber); while(personNumber>MAXNUM || personNumber<0) {  printf("\n你输入的数字无效,请输入在0到%d的整数"MAXNUM);  scanf("%d"&personNumber); } printf("本次求约瑟夫环的出列顺序人数为%d人。\n"personNumber); return personNumber;}int GetPassword(){   /@@*给每个人赋密码函数*/ int password; static int count=1; printf("请输入第%d人的密码:"count); scanf("%d"&password); while (password > MAXPV || password<0); {  printf("您输入的数字无效,请输入在0到%d的整数:"MAXPV);  scanf("%d"&password); } count++; return password;}int GetFirstValue(){   /@@*确定开始的上限值函数*/ int firstValue; printf("请输入密码的上限值:");  scanf("%d"&firstValue); while (firstValue>MAXFV || firstValue<0) {  printf("\n你输入的密码无效,请输入在0到%d的整数:"MAXFV);  scanf("%d"&firstValue); } printf("最终的密码上限值为%d。\n"firstValue); return firstValue;}void GetOutputOrder(linkList *L int personNumber int reportValue int array[MAXNUM]){   /@@*得到出列顺序函数*/  linkList *p*q; int count=1 i=0; p=L; while (personNumber) {  while (count !=reportValue)  {   q=p;   p=p->next;   count++;  }  array[i++]=p->data;  reportValue=p->password;  q->next=p->next;  free(p);  p=q->next;  count=1;  personNumber--; }}void printResult(int array[]int personNumber){   /@@*输出结果函数*/ int i; printf("\n按每人持有的编号依次出列的顺序为:"); for(i=0; i<personNumber; i++)  printf("%-3d"array[i]); printf("\n");}main(){ linkList *L; int personNumber reportValue; int array[MAXNUM]; printf("约瑟夫环问题。\n"); personNumber=GetPersonNumber();  reportValue=GetFirstValue(); L=CreatList(); InitList(L personNumber); GetOutputOrder(L personNumber reportValue array); printResult(array personNumber); system("pause"); return 0;}不知道那错了 最后的出列顺序也没问题,为什么说输入的数字无效  求指点

C语言char *s用法

这个程序表示什么意思 尤其是char*s这一行

C语言中宏定义有什么特别的作用吗

C语言中宏定义有什么特别的作用吗

C语言程序逻辑计算问题

b1=*k+b2; return(b);        可以理解为b=b1,然后返回到第一个式子中的b2出吗?         

C语言编程的问题

C语言中time()函数代表什么意思,用法

C语言指针的问题

一直不明白指针到底方便到哪里;不是程序越少越方便吗?

C语言中指针的学习

指针要怎么学习,感觉好难 有没有好的方法

C语言

指针是不是在C语言中很重要,最近学的指针都不太懂