lains88 2021-10-15 17:13 采纳率: 0%
浏览 8
已结题

关于约瑟夫环鲁棒性完善的问题

img

img

img

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>

typedef int ElemType;

typedef struct Node
{
ElemType data;
int num;
struct Node *next;
}Node,*Link;

enum Color
{
black,blue,green,lakeblue,red,purple,yellow,white,gray,
lightblue,lightgreen,lightsimplegreen,lightred,lightpurple,lightyellow,brightwhite
};

void color(const unsigned short textColor)
{
if(textColor>0 && textColor<15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),textColor);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0);
}

bool InitList(Link &L)
{
L=(Node *)malloc(sizeof(Node));
L->data=0;
L->num=0;
L->next=L;
}

bool ListEmpty(Node *L)
{
if(L->next==L)
return true;
else
return false;
}

int Error()
{
int run();
color(red);
printf("\n最唗堤渣,潰脤蠟腔怀硉\n\n");
printf("潰聆善最唗堤渣ㄛ最唗撈蔚笭......\n\n");
Sleep(1500);
color(brightwhite);
printf(" 求求求求求求求求求求求求求求求求求求求求求求求求求\n\n");
Sleep(1000);
run();
}

bool CreateList(int n,Link &L)
{
Link p,q;
q=L;
if(ListEmpty(q)==true)
{
printf("\n甡棒怀涴%d跺腔場宎躇鎢\n",n);
printf("藩棒怀俇傖綴瑩珨棒隙陬ㄩ\n\n");
for(int i=1;i<=n;i++)
{
p=(Node *)malloc(sizeof(Node));
scanf("%d",&p->data);
p->num=i;
L->next=p;
L=p;
}
L->next=q->next;
free(q);
}
else
Error();
}

void Output(Link &L,int m,int n)
{
Link p,q;
p=L;
if(ListEmpty(q)==false)
{
color(green);
printf("\n堤蹈佼唗峈ㄩ");
for(int i=1;i<=n;i++)
{
for(int i=1;i<m;i++)
p=p->next;
q=p->next;
m=q->data;
printf("%d ",q->num);
p->next=q->next;
free(q);
}
}
else
Error();
}

void UI()
{
system("color 0F");
printf(" 埮阞痲遠\n\n");
printf("�求求求求求求求求求求求求求求求求求求求求求求求求�\n");
printf("�寞寀ㄩ晤瘍岆1ㄛ2ㄛ##n腔n跺偌桽佼奀渀源砃峓 �\n");
printf("�釴珨ㄛ藩跺硐衄珨跺躇鎢ㄗ淏淕杅ㄘ﹝珨羲宎恁�\n");
printf("�珨跺淏淕杅釬峈惆杅奻癹硉m,植菴珨跺羲宎佼奀渀 �\n");
printf("�源砃赻1羲宎佼唗惆杅ㄛ惆善m奀礿砦惆杅﹝惆m腔堤 �\n");
printf("�蹈ㄛ蔚坻腔躇鎢釬峈陔腔m硉ㄛ植坻婓佼奀渀源砃腔狟 �\n");
printf("�珨跺羲宎笭陔植1惆杅ㄛ森狟ㄛ眻善垀衄窒 �\n");
printf("�堤蹈峈砦﹝ �\n");
printf("�求求求求求求求求求求求求求求求求求求求求求求求求�\n\n");
}

int run()
{
Link L,p,q;
int m=0,n=0;
L=NULL;
UI();
InitList(L);
printf("恁寁珨跺淏淕杅釬峈惆杅奻癹硉ㄩ");
int debug1= scanf("%d",&m);
if(!debug1)
Error();
printf("\n怀軞杅ㄩ");
int debug2=scanf("%d",&n);
if(!debug2)
Error();
CreateList(n,L);
Output(L,m,n);
printf("\n");
return 0;
}

int main()
{
run();
return 0;
}

现在问题出现在如果输入一个字母例如o,它就会一直循环报错,我尝试以内存释放,函数封装等方面入手,但还是无功而返。(图片是有中文的部分)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 10月23日
    • 创建了问题 10月15日

    悬赏问题

    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路